问题
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