简体   繁体   中英

Determine the closest available cloud function region from client

I have a firebase cloud function deployed in multiple regions. I need to call the function from a client and the firebase docs state that I must specify the region to call from the client. I'm trying to figure out how to always call the endpoint closest to the client.

What would be the best way to do this with JS on web clients? Is there a way of using the browser IP or timezone to guess the region and map that to EU vs US?

Thanks,

Cloud function definition:

export const admin =  functions
    .region("us-central1", "europe-west2")
    .https.onCall(app);

Client region selection (need to make this dynamic)

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

You can generally select regions close to your users, but you should also consider the location of the other products and services that your app uses. Using services across multiple regions can affect your app's latency, and pricing .
By default, functions run in the us-central1 region. Note that this may be different from the region of an event source, such as a Cloud Storage bucket. If you need to change the region where a function runs, follow the recommendations in the section for best practices for changing region each function according to the trigger type.The available regions for functions do not always match precisely with the regions available for your Cloud Firestore database and your Cloud Storage buckets.Note that if your function and your resource (database instance or Cloud Storage bucket) are in different locations, then you could potentially experience increased latency and billing costs .
If you are using HTTP functions to serve dynamic content for Firebase Hosting , you must use us-central1.

Check these useful documentation for more information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM