how to test Cloud Functions for Firebase locally on pc

前端 未结 9 1482
耶瑟儿~
耶瑟儿~ 2020-11-27 16:39

Today Firebase released its brand new product Cloud Functions for Firebase and I just created a hello world function and deploy it on my existing firebase project.

I

9条回答
  •  情深已故
    2020-11-27 17:05

    For vscode users debugging HTTP functions (webhooks, etc)...

    The google cloud emulator (firebase serve --only functions) launches a separate process to run your functions. You can attach to this process with vscode, but since the emulator only creates this process after the first function is called, it's not straightforward.

    • create a dummy HTTP endpoint in your functions which will return the processID:
    app.get("/processid", function(request, response) {
      response.send(`${process.pid}`);
    });
    
    • start the emulator with firebase serve --only functions
    • call the http:///processid endpoint. This will create the process and return the processID
    • use vscode to attach to the specified process. You can now set breakpoints, step, etc on any of the other functions (they all use the same process).

    There's probably a nicer way to glue all this together.

提交回复
热议问题