2

我正在编写一个带有 firebase 托管和云功能的简单网络应用程序。我的功能是 onCreate 、 onDelete 和 httpsServer。我不想通过在本地运行它来测试我的应用程序。我怎么能做到这一点,因为firebase serve只适用于 https 功能和托管。

我曾尝试在不同的 bash 终端firebase servefirebase 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 终端。

4

1 回答 1

0

我对firebase文档进行了一些挖掘,但找不到任何解决方案。这可能是因为没有官方工具可以让您执行此操作。所以我终于通过使用 nodemon 运行托管然后使用

firebase 服务 --functions

这解决了使用相同端口的问题,因为它是由 nodemon 处理的。

希望firebase将来会提供新的工具。

于 2019-05-12T06:27:49.580 回答