firebase可调用函数返回CORS错误并且不从客户端调用



我使用firebase函数已经有一段时间了,所有函数的部署都非常顺利。突然之间,部署的任何新函数都停止了工作,来自客户端的任何调用都返回CORS错误。如果我查看firebase面板中的函数列表,我看不到被调用的函数,这与我所期望的函数根本不存在的情况类似。

我现在只是在尝试一个简单的基本功能,如下所示:

exports.createSession = functions.region('europe-west2').https.onCall(async (data, context) => {
return ({status: 200})
});

在前端,我正在做一个简单的调用,如下所示:

const createSessionFunction = functions.httpsCallable('createSession');
const response = await createSessionFunction({});

本周之前创建和部署的所有其他功能都运行良好。没有任何新功能。

我得到的错误如下:

Access to fetch at 'https://europe-west2-xxxxxxx.cloudfunctions.net/createSession' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
index.cjs.js:614 POST https://europe-west2-xxxxxxxz.cloudfunctions.net/createSession net::ERR_FAILED

我在firebase GUI上的功能列表显示这个功能确实存在:

createSession - Request - https://europe-west2-xxxxxxxx.cloudfunctions.net/createSession-europe-west2-Node.js 8 -256 MB - 60s

然而,日志显示,当我尝试测试它时,它从未从客户端调用过,这意味着客户端可能根本没有检测到这个函数。

我尝试了以下步骤,但没有成功:

  1. 删除并重新部署函数
  2. 重命名函数并重新部署
  3. 在不同的应用程序上部署相同的新功能(dev/test等(

有什么想法吗?

这是在谷歌云仪表板上通过授予我的所有功能公共访问权限解决的。默认权限已从公用更改为专用。

https://cloud.google.com/functions/docs/securing/managing-access-iam#allowing_unauthenticated_function_invocation

最新更新