我按照授权的https-endpoint样本,只添加了console.log来打印req.cookies,问题是cookie总是空的{}我使用客户端JS调用设置cookie但他们确实保存但是由于某些原因,我可以不要让他们在服务器端.
这是index.js的完整代码,它与示例完全相同:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const express = require('express');
const cookieParser = require('cookie-parser')();
const cors = require('cors')({origin: true});
const app = express();
const validateFirebaseIdToken = (req, res, next) => {
console.log(req.cookies); //// <----- issue this is empty {} why??
next();
};
app.use(cors);
app.use(cookieParser);
app.use(validateFirebaseIdToken);
app.get('/hello', (req, res) => {
res.send(`Hello!!`);
});
exports.app = functions.https.onRequest(app);
Run Code Online (Sandbox Code Playgroud)
商店cookie:
curl http://FUNCTION_URL/hello --cookie "__session=bar" // req.cookies =
{__session: bar}
不存储:
curl http://FUNCTION_URL/hello --cookie …
javascript cookies firebase firebase-hosting google-cloud-functions
我有一个 Firebase 托管的单页应用程序。
我还有 3 个 Firebase 功能(联系人、计划、功能),应用程序和外部资源会向我提出请求。
我的应用程序有一个自定义域,我想通过它访问我的功能。
这是我目前的firebase.json配置
{
"hosting": {
"public": "www",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
所以目前所有流量都流向我的应用程序,路由是通过我的 SPA 处理的。目前必须通过cloudfunctions.net不理想的URL访问我的功能。
如何向此配置添加 URL 重写条目,以便我的功能可以通过我的自定义域访问并且我的单页应用程序处理其余的路由?
我已经为features端点尝试了以下方法:
"rewrites": [
{
"source": "/features/**",
"function": "features"
},
{
"source": "!/features/**",
"destination": "/index.html"
}
]
Run Code Online (Sandbox Code Playgroud)
在我的功能中,index.js我有:
{
"hosting": {
"public": "www",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
} …Run Code Online (Sandbox Code Playgroud) firebase single-page-application firebase-hosting google-cloud-functions