【发布时间】:2019-03-29 11:07:57
【问题描述】:
我正在编写一个带有 Firebase 托管和云功能的简单网络应用程序。我的功能是 onCreate 、 onDelete 和 httpsServer。我不想通过在本地运行它来测试我的应用程序。我该怎么做,因为firebase serve 只适用于 https 功能和托管。
我曾尝试在不同的 bash 终端上同时运行 firebase serve 和 firebase functions:shell。这会导致firebase functions:shell 失败。
创建函数:
exports.created = functions.firestore.document('Books/{bookID}')
.onCreate((snapshot, context) => {
FUNCTION_BODY
});
删除功能:
exports.deleted = functions.firestore.document('Books/{bookID}')
.onDelete((snapshot, context) => {
FUNCTION_BODY
});
https 功能:
exports.app = functions.https.onRequest(app);
bash 抛出的错误:
$ firebase functions:shell
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.13.0 but Google Cloud Functions only supports v6.11.5.
! functions: Failed to emulate created
! functions: Failed to emulate deleted
! functions: Failed to emulate app
i functions: No functions to emulate.
No functions emulated.
第二个 bash 的输出:
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.13.0 but Google Cloud Functions only supports v6.11.5.
i hosting: Serving hosting files from: public
+ hosting: Local server: http://localhost:5000
info: initalised
info: rendering home...
+ functions: app: http://localhost:5001/book-shelf-be347/us-central1/app
info: Worker for app closed due to file changes.
注意:这些是在同一台机器上同时运行的独立 bash 终端。
【问题讨论】:
-
如果无法使用基于火的工具,其他替代方法也可以。
-
可能类似于 nodemon。
标签: javascript firebase google-cloud-functions firebase-hosting