How to test `functions.https.onCall` firebase cloud functions locally?

后端 未结 6 713
悲哀的现实
悲哀的现实 2020-12-01 07:42

I can\'t seem to find the solution for this in the Firebase Documentation.

I want to test my functions.https.onCall functions locally. Is it possible usi

6条回答
  •  离开以前
    2020-12-01 08:08

    you should first check for dev environment and then point your functions to local emulator.
    For JS:

    //after firebase init
    if (window.location.host.includes("localhost") ||
        window.location.host.includes("127.0.0.1")
    ) {
        firebase
          .app()
          .functions()  //add location here also if you're mentioning location while invoking function()
          .useFunctionsEmulator("http://localhost:5001");
      }
    

    or if you don't create instance of firebase then

    //after firebase init
    if (window.location.host.includes("localhost") || 
       window.location.host.includes("127.0.0.1")
    ) {
        firebase
          .functions()
          .useFunctionsEmulator("http://localhost:5001");
      }
    

    or when serving pages from backend (node.js):

    //after firebase init
    if (process.env.NODE_ENV === 'development') {
      firebase.functions().useFunctionsEmulator('http://localhost:5001');
    }
    

提交回复
热议问题