我有三个云功能,其中两个已部署到我的 firebase 项目中,其中一个是我刚刚添加的。我希望在部署之前在本地测试新的功能,但是当我尝试使用它时却无法使用,并且只有两个已部署的功能可用。
Firebase 模拟器在端口上运行良好5001
,像往常一样。我跟着这些说明 https://firebase.google.com/docs/functions/local-emulator#instrument_your_app_for_https_functions_emulation并添加了firebase.functions().useEmulator("localhost", 5001);
到我想在本地测试的函数:
已部署的 func 示例:
// index.js
exports.addMessage = functions.region("europe-west1").https.onRequest(...
尚未部署的功能:
// index.js
exports.testFunction = functions.useEmulator("localhost", 5001).https.onRequest(...
然后我去了https://localhost:5001/{projectId}/us-central1/testFunction
,但浏览器显示一条消息仅表示addMessage
我的其他部署功能可供使用。我也尝试过http
,正如另一个线程中所建议的那样。
我这里缺少一个步骤吗?某种“本地”部署?我知道 firebase 版本发生了一些变化,这可能会把事情搞砸,但我在运行时使用 firebase 安装的默认导入/依赖项firebase init
:
// package.json
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
//index.js
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";