代码之家  ›  专栏  ›  技术社区  ›  Devin Carpenter Assaf Hershko

如何在Firebase Cloud函数中调用导出的https Firebase Cloud函数?

  •  0
  • Devin Carpenter Assaf Hershko  · 技术社区  · 6 年前

    我现在有一个从客户端调用的函数,现在我还需要从Firebase云函数调用它。

    我需要调用的函数的语法是

    exports.querySomeAPI = functions.https.onCall((data)=>{
        //Does work and returns stuff
    });
    

    我从客户端用

    var querySomeAPI = firebase.functions().httpsCallable('querySomeAPI');
    querySomeAPI({
        data: "data"
    }).then(response => {console.log("Query Response is: ", response);});
    

    因为firebase没有在我的后端定义,所以我尝试用

    var querySomeAPI = admin.functions().httpsCallable('querySomeAPI');
    querySomeAPI({
        data: "data"
    }).then(response => {console.log("Query Response is: ", response);});
    

    querySomeAPI({
        data: "data"
    }).then(response => {console.log("Query Response is: ", response);});
    

    以及其他一些方法都无济于事。我知道必须有一种方法从Firebase函数中调用导出函数,但迄今为止我尝试的方法都不起作用。

    有人知道怎么做吗?

    Link for how to call the https callable function on the clientside

    1 回复  |  直到 6 年前
        1
  •  2
  •   Doug Stevenson    6 年前

    如果您试图直接从这样的另一个函数调用一个函数,您会遇到很多麻烦(而且不必要地增加账单)。您最好只创建一个简单的JS函数,您的两个云函数导出可以彼此独立地共享。

    看这个: Calling a Cloud Function from another Cloud Function