Firebase可调用函数返回CORS错误且未从客户端调用

时间:2020-03-26 20:46:51

标签: firebase google-cloud-functions

我使用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. 在不同的应用程序(开发/测试等)上部署相同的新功能

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

通过授予我所有功能公共访问权限,这已在Google云仪表板上解决。默认权限已从公共更改为私人。

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

相关问题