javascript - 如何确保 Web 应用程序使用具有正确 URL 的 firebase 函数模拟器进行测试
问题描述
我正在尝试测试 google firebase oncall 功能,因此创建了一个带有 google 身份验证的基本 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 POST http://http//localhost:5001:undefined/myProject/us-central1/myFunction net::ERR_NAME_NOT_RESOLVED
模拟器提供的实际网址:
http://localhost:5001/myProject/us-central1/myFunction.myFunction
这显然是行不通的。如何清理此 URL?
解决方案
首先,确保初始化应用程序客户端,并尝试useFunctionsEmulator:
const app = window.firebase.initializeApp(config)
app.functions().useFunctionsEmulator("http://localhost:5001");
推荐阅读
- javascript - 在 React Web 应用程序中通过数组映射返回“未定义”
- javascript - 如何使用 alpha beta 剪枝实现转置表
- python-3.x - 为什么我不能制作具有大量值的相关矩阵
- arrays - 如何复制字节数组
- vb.net - 是否可以将 VB.Net MDI 子窗体移动到另一个屏幕?
- python - 在 Pandas df 行中查找值并返回列名
- python - 如何使用正则表达式将字符串拆分为不同长度的块
- android - 询问用户是否允许录制音频、读取手机状态和前台服务?
- batch-file - 在 2 个预定义路径之间选择对话框
- arrays - 在 Kotlin 中调用布尔数组的第 6 个元素