firebase云函数不会存储除了"__session"以外的cookie。

10 浏览
0 Comments

firebase云函数不会存储除了"__session"以外的cookie。

我按照authorized-https-endpoint的示例进行了操作,并添加了console.log来打印req.cookies,但问题是cookies始终为空{}。我使用客户端的JS调用设置了cookies,它们确实保存了下来,但出于某种原因,我无法在服务器端获取它们。

下面是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); //// <----- 问题是这里为空{},为什么?

next();

};

app.use(cors);

app.use(cookieParser);

app.use(validateFirebaseIdToken);

app.get('/hello', (req, res) => {

res.send(`Hello!!`);

});

exports.app = functions.https.onRequest(app);

存储cookie:

curl http://FUNCTION_URL/hello --cookie "__session=bar" // req.cookies =
 {__session: bar}

未能存储:

curl http://FUNCTION_URL/hello --cookie "foo=bar" // req.cookies =
 {}

0