Reputation: 325
For example, my firebase cloud functions URL will be different in my emulator instance, my development Firebase project (online), and my production Firebase project (online).
On the client side, I would hardcode the URL and change the URL for each invocation upon deployment to match the function HTTP URL for the particular environment I am in. This is unsustainable and tedious. For example, if I had 10 invocations I would have to go through and change the fetch URLS each time I changed environments. If I wanted to test them in a non-prod environment later I would have to change them back. Is there any solution to this, I am using one codebase.
Per Google Cloud docs, eventually, the functions will feature deterministic URLS which means I can programmatically do this in the future using the .env. files but until then I'm not sure how to do this.
TLDR I am trying to make it so that regardless of the environment the client is in it will be able to use the same URL across them to execute the respective function. i.e a DEV client would execute a DEV cloud function that would communicate with DEV servers.
Upvotes: 0
Views: 148
Reputation: 81454
There are several options:
Use Firebase Hosting. See this answer.
Migrate your functions to Cloud Run and use custom domains.
My preference is the third option, as Cloud Run is the big brother to Cloud Functions with many features that I wish Cloud Function had.
Firebase Hosting is another good option that brings another set of features for web-based applications.
The first option is a good choice for hiding Functions behind a proxy that protects your functions.
Upvotes: 1