我有一个简单的 Firebase 函数,如下所示。当通过 javascript (CORS) 访问时,该函数的飞行前选项的请求(CORS 标准的一部分)将返回 302 重定向到以以下内容开头的 url
https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3D
并以我的函数的 URL 结尾。这是有问题的整个函数:
import * as functions from 'firebase-functions';
import * as express from 'express';
import * as cors from 'cors';
const app = express();
app.use(cors({ origin: true }));
app.post('*', async (req, res) => {
res.setHeader('X-Test', 'OK');
res.setHeader('Set-Cookie', ['__session=ninja']);
res.send('OK');
});
app.get('*', async (req, res) => {
res.setHeader('X-Test', 'OK');
res.setHeader('Set-Cookie', ['__session=ninja']);
res.send('OK');
});
export const testing = functions.https.onRequest(app);
正如您所看到的,该函数不包含任何重定向逻辑。如果我手动导航到浏览器中的重定向链接(accounts.google.com
一),它显示某种 Google Compute Engine 安全页面,要求访问我的 Google 帐户。最近,当我通过 javascript 访问它们时,之前工作的所有函数都开始使用此 302 重定向进行回复。这导致我的所有功能无法按预期工作。
我不能确定,但我think它是在我尝试使用 Google Cloud Functions cli(而不是 Firebase Functions cli)发布函数后开始的。感觉就像使用发布一个函数gcloud
cli 可能触发了某种设置更改?我找不到关于这个问题的任何信息。
任何帮助是极大的赞赏!