[英]How can I configure my firebase config to access the firebase emulator functions endpoint?
Prerequisites:先决条件:
I'd like to connect my Vue.js Frontend with my local firebase functions emulator.我想将我的 Vue.js 前端与我的本地 firebase 函数仿真器连接起来。 The emulator is located at
localhost:5001
.模拟器位于
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.我开始更改
cloudFunctionBaseUrl
,因为使用此属性更改函数端点 url 对我来说很明显。 As you can see I set it to localhost:5001/...
.如您所见,我将其设置为
localhost:5001/...
。 However the url being used in my app still was calling this url:然而,在我的应用程序中使用的 url 仍然调用这个 url:
https://us-central1-company-bar.cloudfunctions.net
I figured out that the url is being composed by the projectId
property of the configuration.我发现 url 是由配置的
projectId
属性组成的。 The cloudFunctionBaseUrl
therefore is not overwriting it at all. cloudFunctionBaseUrl
因此根本不会覆盖它。
How can I now change the composed url我现在如何更改组合的 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.我希望有某种配置标志,例如
enableEmulator
或类似的东西,但在文档中找不到任何提示。
You're correct in thinking there's a function, its called useEmulator
.您认为有一个 function 是正确的,它被称为
useEmulator
。 You have to call it for each part of firebase you want to emulate as far as I'm aware.据我所知,您必须为要模拟的 firebase 的每个部分调用它。
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.在
firebase.initializeApp
调用之后。
More information can be found on the official docs: https://firebase.google.com/docs/emulator-suite/connect_functions#更多信息可以在官方文档中找到: https://firebase.google.com/docs/emulator-suite/connect_functions#
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.