如何确保web应用程序使用具有正确URL的firebase函数模拟器进行测试



我正在尝试测试一个谷歌firebase oncall函数,因此创建了一个带有谷歌身份验证的基本vue应用程序。我添加了以下行以确保模拟器被使用,并且我可以在本地进行测试:

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

我在应用程序和我拥有的功能中有firebase 8.2.0:

"firebase-admin": "^8.10.0"
"firebase-functions": "^3.12.0"

该应用程序使用以下代码调用该函数:

var callFunction = firebase
.functions()
.httpsCallable("myFunction");
callFunction({
dataItem: "xxxxxxxxxxxxxxxx"
})
.then(result => {
console.log(result);
})
.catch(error => {
console.log(error);
});

当该功能在应用程序中触发时,会生成以下错误:

index.esm.js?7dc7:490 POSThttp://http//localhost:5001:undefined/myProject/us-central1/myFunctionnet::ERR_NAME_NOT_RESOLVED

模拟器提供的实际URL:

http://localhost:5001/myProject/us-central1/myFunction.myFunction

这显然不起作用。如何清理此URL?

首先,确保初始化应用程序客户端,并尝试useFunctionsSimulator:

const app = window.firebase.initializeApp(config)
app.functions().useFunctionsEmulator("http://localhost:5001");

最新更新