【发布时间】:2019-11-10 21:54:42
【问题描述】:
我尝试使用 firebase emulator:start 在本地计算机上测试我的 google firebase 云功能。然而,云函数的本地实例并未被执行,而是 Google Cloud 上的实例被执行。
我按照以下步骤设置模拟器:https://firebase.google.com/docs/functions/local-emulator
$ export GOOGLE_APPLICATION_CREDENTIALS='path/tofile'
$ firebase setup:emulators:firestore
$ firebase init firestore
$ export FIRESTORE_EMULATOR_HOST=localhost:8080
$ firebase emulators:start
Starting emulators: ["functions","firestore","hosting"]
⚠ Your requested "node" version "8" doesn't match your global version "10"
✔ functions: Emulator started at http://localhost:5001
i firestore: Logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
✔ hosting: Emulator started at http://localhost:5000
i hosting: Serving hosting files from: www
✔ hosting: Local server: http://localhost:5000
i functions: Watching "/home/borch/Documents/Ionic/myproject/functions" for Cloud Functions...
i functions: Setting up Cloud Firestore trigger "myGCFunction"
✔ functions: Trigger "myGCFunction" has been acknowledged by the Cloud Firestore emulator.
如您所见,触发器已被 Cloud Firestore 模拟器识别。
但每次调用 myGCFunction 时都会执行的函数是 Google Cloud 上的函数。我认为它应该从我在 localhost:8080 运行的本地 API 执行函数,对吗?
我意识到只有云上的函数会被执行,因为我检查了 firebase 函数控制台并查看了该函数执行的新记录。
我将 firebase-admin 和 firebase-functions 更新到了最新版本:
$ cat functions/package.json | grep firebase-
"firebase-admin": "^8.2.0",
"firebase-functions": "^3.0.2",
谢谢。
【问题讨论】:
-
你是如何触发myGCFunction函数的?
-
我正在使用模拟器提供的本地主机,网址为 localhost:5000 当 Firestore 上有新文档时触发 myGCFunction。
标签: firebase google-cloud-functions firebase-admin firebase-cli firebase-tools