Firebase cloud function onCall not working after changing region

混江龙づ霸主 提交于 2020-05-14 21:37:24

问题


I built few cloud functions like this one:

const addRoom = functions.https.onCall((data, context) => {

It works perfectly but I wanted to change region to europe-west. I followed this stackoverflow: firebase deploy to custom region (eu-central1)

const addRoom = functions.region('europe-west1').https.onCall((data, context) => {

It looks working fine for all functions (triggers) except onCall functions. I got this error when calling addRoom function on client side :

firebase.functions().httpsCallable("addRoom")(data)

Access to fetch at 'https://us-central1-myproject.cloudfunctions.net/addRoom' from origin 'http://localhost:4200/new-room' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

At this moment I use default region for onCall functions but is there a way to correct that or is that an error from firebase ?


回答1:


On the client side, you should specify the desired region at initialization and call the function as follows:

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

....

functions.httpsCallable("addRoom")(data)

See https://firebase.google.com/docs/functions/locations#http_and_client_callable_functions



来源:https://stackoverflow.com/questions/54389993/firebase-cloud-function-oncall-not-working-after-changing-region

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!