【问题标题】:Firebase cloud function always fails - onerrorFirebase 云功能总是失败 - onerror
【发布时间】:2017-10-02 16:00:20
【问题描述】:

我正在尝试通过服务功能(testing locally)使用xmlhttprequest调用firebase云功能,以下代码是xmlHttpRequest

var req = new XMLHttpRequest();
req.onload = function() {
    //success
};
req.onerror = function() {
    //always fall to this function
};
var url = 'https://us-central1-' + getFirebaseProjectId() + '.cloudfunctions.net/helloWorld';
req.open('GET', url);

//Chrome does not allow 'Access-Control-Allow-Origin' from 
//localhost:5000 (non-google server)

//I am using mozilla firefox with 'serve' feature, hope 
//this solve 'Access-Control-Allow-Origin' problem

req.setRequestHeader('Access-Control-Allow-Origin', '*');
req.send();

我可以看到云功能在 firebase 控制台中成功执行。但我总是陷入 onerror 函数。

我还通过

在云功能中启用了 CORS
const cors = require('cors')({origin: true});

在本地托管功能时出现以下错误

经过两天的调研,

  • 已将节点和 Firebase 更新为兼容版本。
  • 已清除缓存
  • 通过 npm 更新了 firebase-tools、firebase 功能

。还是不行。

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    删除项目,用firebase init function重新初始化项目。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-31
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多