我正在编写一个带有 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 终端。