更改区域后,Firebase 云功能 onCall 不起作用

Cur*_*rse 7 firebase google-cloud-functions

我构建了几个像这样的云函数:

const addRoom = functions.https.onCall((data, context) => {
Run Code Online (Sandbox Code Playgroud)

它运行良好,但我想将区域更改为欧洲西部。我跟着这个stackoverflow:firebase deploy to custom region (eu-central1)

const addRoom = functions.region('europe-west1').https.onCall((data, context) => {
Run Code Online (Sandbox Code Playgroud)

除了 onCall 函数外,它看起来适用于所有函数(触发器)。在客户端调用 addRoom 函数时出现此错误:

firebase.functions().httpsCallable("addRoom")(data)
Run Code Online (Sandbox Code Playgroud)

从源“ http://localhost:4200/new-room ”访问“ https://us-central1-myproject.cloudfunctions.net/addRoom ”已被 CORS 政策阻止:对预检请求的响应没有通过访问控制检查:预检请求不允许重定向。

目前,我对 onCall 函数使用默认区域,但有没有办法纠正它,或者是 firebase 的错误?

Ren*_*nec 13

在客户端,您应该在初始化时指定所需的区域并按如下方式调用该函数:

var functions = firebase.app().functions('europe-west1');

....

functions.httpsCallable("addRoom")(data)
Run Code Online (Sandbox Code Playgroud)

请参阅https://firebase.google.com/docs/functions/locations#http_and_client_callable_functions