【问题标题】:firebase functions stopped working after iamiam 后 firebase 功能停止工作
【发布时间】:2020-03-16 13:05:34
【问题描述】:

我正在尝试做一些非常简单的事情,但是整个 IAM、实时数据库、云功能配置错误让我在一个简单的世界上浪费了数小时的工作时间。

我有一个已经填充的数据库(超过 300 项):

然后我将以下功能部署到 Firebase 云:

const actions = [];
const igDatabase = require('firebase-admin').initializeApp({
   serviceAccountId: 'actionkeeper@igibo-b0b27.iam.gserviceaccount.com'
}).database("https://igibo-b0b27.firebaseio.com/");

let lastMapRefresh = 0;
let lastUpdateFirebase = 0;

function refreshActions(afterRefresh) {
   console.log("refreshing actions");
   igDatabase.ref('actions/').orderByChild('timestamp').startAt(lastMapRefresh).once('value').then(function(data) {
      if (data != null && data.exists()) {
         let bef = actions.length;
         actions.length = 0;
         actions.push(data.val());

         lastMapRefresh = new Date().getTime();        
         afterRefresh();
      }
      console.log("actions refreshed before: " + bef + " now: " + actions.length);
   }).catch(function(error) {
      console.error("Error: " + JSON.stringify(error));
   });
}

exports.decrementAction = (req, res) => {
refreshActions(function() {});
}

这个函数很简单,读取数据库上的一个分支并填充一个数组......这个函数的目的更复杂,但我正在构建它并缓慢测试......即使这个简单的方法也不起作用

该节点的 firebase 规则是:

{
   "rules":{

      "actions":{
         ".indexOn":[
            "timestamp"
         ],
         ".read":"auth != null",
         "$act":{
            "countdown":{
               ".write":"auth != null && data.val() - newData.val() == 1 && newData.val() >= 0"
            }
         }
      }
}
}

所以登录的任何人都可以阅读

在我的 google IAM 控制台中

所以服务帐户应该对数据库具有管理员权限...

但是运行这个函数总是返回 NULL data

为什么?

【问题讨论】:

    标签: firebase firebase-realtime-database google-cloud-functions google-iam google-cloud-iam


    【解决方案1】:

    您的代码似乎并未真正向客户端发送响应。这是你的功能:

    exports.decrementAction = (req, res) => {
        refreshActions(function() {});
    }
    

    它从未使用过res 来发送响应。在默认的 60 秒之后总是会超时,卡在等待您拨打 res.send() 或类似的电话。

    我建议查看HTTP triggers 上的文档以了解如何发送回复。根据refreshFunctions 传递给它的内容,我想您的(当前为空)回调函数需要执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-16
      • 2018-08-25
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      相关资源
      最近更新 更多