firebase deploy to custom region (eu-central1)

前端 未结 5 1445
心在旅途
心在旅途 2020-12-08 06:43

is there a way to specify the Region/Zone where my firebase functions will be deployed.

Actually i didn\'t found anything about that in the documentation and my fun

相关标签:
5条回答
  • 2020-12-08 07:16

    From docs: https://firebase.google.com/docs/functions/locations

    Now available in the following regions:

    • us-central1 (Iowa)
    • us-east1 (South Carolina)
    • europe-west1 (Belgium)
    • asia-northeast1 (Tokyo)

    Best Practices for Changing Region

    // before
    const functions = require('firebase-functions');
    
    exports.webhook = functions
        .https.onRequest((req, res) => {
                res.send("Hello");
        });
    
    // after
    const functions = require('firebase-functions');
    
    exports.webhookEurope = functions
        .region('europe-west1')
        .https.onRequest((req, res) => {
                res.send("Hello");
        });
    
    0 讨论(0)
  • 2020-12-08 07:16
    "rewrites": [
      {
        "source": "**",
        "run": {
          "serviceId": "<service id>",
          "region": "europe-west1"
        }
      }
    ]
    },
    
    0 讨论(0)
  • 2020-12-08 07:20

    firebaser here

    Update (2018-07-25):

    It is now possible to specify the region for your Cloud Functions in Firebase you specify that region in your code and deploy the change. E.g.:

    exports.myStorageFunction = functions
        .region('europe-west1')
        .storage
        .object()
        .onFinalize((object) => {
          // ...
        });
    

    For full details see the Firebase documentation on Cloud Functions locations (from where I got the above snippet) and modifying the region of a deployed function.

    0 讨论(0)
  • 2020-12-08 07:30

    To use the same custom region for all your functions, you do something like this.

    import * as functions from 'firebase-functions';
    
    const regionalFunctions = functions.region('europe-west1');
    
    export const helloWorld = regionalFunctions.https.onRequest((request, response) => {
     response.send("Hello from Firebase!");
    });
    
    export const helloWorld2 = regionalFunctions.https.onRequest((request, response) => {
     response.send("Hello from Firebase 2!");
    });
    
    0 讨论(0)
  • 2020-12-08 07:34

    To have Firebase functions deployed to a region also work in local emulation, one must initialise the client as such:

    const functions = LOCAL ? firebase.app().functions(/*functionsRegion*/) :  
      firebase.app().functions(functionsRegion);
    
    const fun = functions.httpsCallable('your_function_name');
    

    i.e. the code is not the same. Adding a region in the emulated case makes the calls get lost, without an error.

    LOCAL is a client side value I've made to know, whether the back end is running in the cloud, or set up for local emulation.

    Surely, this is a corner case that Firebase will iron away?

    firebase-tools 8.6.0, firebase 7.16.1

    0 讨论(0)
提交回复
热议问题