【发布时间】:2021-08-24 15:45:31
【问题描述】:
我有一个连接到 Firebase 托管的自定义子域 - api.example.com
另外我在 Firebase Functions 中有一个函数
exports.test = functions
.region('europe-west3')
.https.onRequest((request, response) => {
const expiresIn = 60 * 60 * 24 * 5 * 1000;
const origin = request.headers.origin;
const options = { maxAge: expiresIn, httpOnly: true, secure: true, sameSite: 'strict', };
response.cookie('__session', "123456", options);
response.set('Access-Control-Allow-Origin', origin);
response.set('Access-Control-Allow-Credentials', true);
response.end(JSON.stringify({ status: 'success' }));
})
我的 Firebase.json 如下所示
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [{
"source": "/test",
"function": "test"
}]
}
}
现在,当我尝试向https://api.example.com/test 发出 POST 请求时
我收到一个错误
您的客户端无权从此服务器获取 URL /test/test。
这是有道理的,因为 URL 上写着/test/test/
我在这里做错了什么?有什么建议么?谢谢。
【问题讨论】:
标签: javascript firebase cookies google-cloud-functions firebase-hosting