I know this question has been asked many times, and I've read all the answers, but still don't have a working solution.
I try to run my firebase functions and hosting locally with firebase serve
or firebase emulators:start
as described here and here.
This gives me something like:
✔ functions: Using node@8 from host.
✔ functions: Emulator started at http://127.0.0.1:8081
i functions: Watching "/home/ec2-user/environment/functions" for Cloud Functions...
i hosting: Serving hosting files from: build
✔ hosting: Local server: http://127.0.0.1:8080
⚠ functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to XXXXX-d5435114eb69.json. Non-emulated services will access production using these credentials. Be careful!
✔ functions[log]: http function initialized (http://127.0.0.1:8081/XXXXX/us-central1/log).
The hosting server works perfectly, and there is a log
cloud function initialized at http://127.0.0.1:8081/XXXXX/us-central1/log
. But running:
const log = firebase.functions().httpsCallable('log');
log("Hello World");
from the local hosted site tries to call the deployed cloud function and gives me a CORS error:
Access to fetch at 'https://us-central1-XXXXX.cloudfunctions.net/log' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy
I'm using the firebase auto configuration to load the sdk.
Is it possible to run both hosting and functions locally for development?