Joh*_*ohn 6 javascript firebase google-cloud-functions
我有一个简单的 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);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该函数不包含任何重定向逻辑。如果我手动导航到浏览器(第一个)中的重定向链接accounts.google.com,它会显示某种 Google Compute Engine 安全页面,要求访问我的 Google 帐户。最近,当我通过 javascript 访问它们时,之前工作的所有函数都开始使用此 302 重定向进行回复。这导致我的所有功能无法按预期工作。
我不确定,但我认为它是在我尝试使用 Google Cloud Functions cli(而不是 Firebase Functions cli)发布函数后开始的。感觉就像使用gcloudcli 发布一个函数可能会触发某种设置更改?我找不到关于这个问题的任何信息。
任何帮助是极大的赞赏!
Joh*_*ohn 11
天哪,问题是我的函数名称有一个拼写错误!该函数的名称是userAccount-testing,我正在调用userAccount.testing。显然,当你调用一个不存在的函数时,你会得到 302 重定向作为响应。
在尝试诊断此问题时,我复制并粘贴了不同的函数名称,但碰巧从未将其更新.为-. 脸掌
| 归档时间: |
|
| 查看次数: |
1602 次 |
| 最近记录: |