简体   繁体   中英

How can I configure my firebase config to access the firebase emulator functions endpoint?

Prerequisites:

  • Firebase SDK: ^7.21.1

I'd like to connect my Vue.js Frontend with my local firebase functions emulator. The emulator is located at localhost:5001 . I have a hard time figuring out what configuration properties I have to set to access the emulator endpoint.

Here is my current configuration:

const firebaseConfig = {
  apiKey: "AIzaSyCKvB9ZluNGOP4s4r8igflwuK-9WVsoThg",
  authDomain: "company-29f5c.firebaseapp.com",
  databaseURL: "https://company-29f5c.firebaseio.com",
  projectId: "company-bar",
  storageBucket: "company-29f5c.appspot.com",
  messagingSenderId: "1051704079600",
  appId: "1:1051704079600:web:f99d362c43b87346",
  notificationWebhookUrl: "http://localhost:5001/company-dev/us-central1/notificationsMixpanelWebhook",
  cloudFunctionBaseUrl: "http://localhost:5001/company-dev/us-central1",
};

I started changing the cloudFunctionBaseUrl since it kind of was obvious for me to use this property to change the functions endpoint url. As you can see I set it to localhost:5001/... . However the url being used in my app still was calling this url:

https://us-central1-company-bar.cloudfunctions.net

I figured out that the url is being composed by the projectId property of the configuration. The cloudFunctionBaseUrl therefore is not overwriting it at all.

How can I now change the composed url

https://us-central1-company-bar.cloudfunctions.net

to

http://localhost:5001/company-dev/us-central1

I expect that there is some kind of configuration flag like enableEmulator or something like that but could not find any hint in the docs for that.

You're correct in thinking there's a function, its called useEmulator . You have to call it for each part of firebase you want to emulate as far as I'm aware.

If you want to make functions use the emulator you can do something like the following:

firebase.functions().useEmulator('localhost', 5001);

After the firebase.initializeApp call.

More information can be found on the official docs: https://firebase.google.com/docs/emulator-suite/connect_functions#

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