Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Localhost Firebase Cloud Functions are working with the emulator but not live

I have a Firebase app with an App Check debug token implemented.

When I run my Cloud Functions using the Emulator they work fine.

But when I turn off the emulator and try to access the live deployed version from http://localhost:8080/ I get this console error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

POST http://localhost:5001/my-app/us-central1/getZohoDeskTicketsLoggedInUser net::ERR_CONNECTION_REFUSED

Why does this happen when calling the live version and not with the emulator?

There are no Firebase Cloud Function logs to provide because the functions never even fire.

Perhaps I need to white list the locahost domain somewhere?

>Solution :

When you deploy your web app to productions, you should use URL of deployed Cloud function to make your API requests instead of localhost which will lead to connection errors. You can additionally call connectFunctionsEmulator only when you are on localhost:

if (window.location.hostname === "localhost") {
  connectFunctionsEmulator(...)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading