代码之家  ›  专栏  ›  技术社区  ›  SpaceX

调用firebase函数会导致内部错误

  •  0
  • SpaceX  · 技术社区  · 5 年前

    我也看到过类似的问题,但它们没有回答我面临的问题。

    我可以确认这个功能已经部署到了firebase上。

    通过在浏览器中粘贴下面的链接,我得到了一个响应。 https://us-central1-cureme-dac13.cloudfunctions.net/helloWorld

    索引.js 文件包含代码(Firebase cloud函数在index.js中定义)

    const functions = require('firebase-functions');
    
    exports.helloWorld = functions.https.onRequest((request, response) => {
        response.send("Hello from Firebase!");
    });
    

    具有以下代码(客户端/网站)

    var messageA = firebase.functions().httpsCallable('helloWorld');
    
    messageA().then(function(result) {
    
      console.log("resultFromFirebaseFunctionCall: "+result)
    
    }).catch(function(error) {
      // Getting the Error details.
      var code      = error.code;
      var message   = error.message;
      var details   = error.details;
      // ...
      console.log("error.message: "+error.message+" error.code: "+error.code+" error.details: "+error.details)
      // Prints: error.message: INTERNAL error.code: internal error.details: undefined
    });
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Renaud Tarnec    5 年前

    你搞混了 Callable Cloud Functions HTTPS Cloud Functions

    通过做

    exports.helloWorld = functions.https.onRequest(...)
    

    你定义了一个HTTPS云函数,

    但是通过做

    var messageA = firebase.functions().httpsCallable('helloWorld');
    messageA().then(function(result) {...});
    


    您应该将云函数更改为可调用的,或者调用/调用 helloWorld 通过向云函数URL发送HTTP GET请求(类似于您在浏览器中通过“粘贴 https://us-central1-cureme-dac13.cloudfunctions.net/helloWorld 浏览器中的链接)。

    Axios 图书馆,你可以:

    axios.get('https://us-central1-cureme-dac13.cloudfunctions.net/helloWorld')
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      })