Firebase云功能未运行

时间:2017-12-25 06:35:52

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

我从Firebase Cloud Functions获得了一些意想不到的行为,而下面的函数似乎没有运行。我的期望是/posts端点中的数据将记录到控制台。我在部署函数时没有错误。

该函数用于客户端/用户未参与的仅后端操作,因此基于数据库事件或https的触发器对我无效,无需设置另一个服务器来调用端点。

下面有什么理由不记录吗?

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


 getScheduledPosts = () => {
           admin.database().ref("/posts")
          .orderByKey()
          .once("value")
          .then( (snapshot) => {
              console.log(snapshot);
           })
           .catch(err => {console.log(err)});
          console.log("Posts Ran")
      }

  // Call this function 
  getScheduledPosts();

1 个答案:

答案 0 :(得分:2)

您根本没有定义云功能。由于您没有定义任何云功能,因此您编写的代码将永远无法运行。您必须从index.js导出一个,并且必须使用firebase-functions SDK构建其定义。如果您正在尝试创建database trigger(肯定会在那里阅读文档),它看起来像这样:

exports.makeUppercase = functions.database.ref('/posts/{id}')
    .onWrite(event => {
  // do stuff here
})

不要尝试做一次性的""部署函数时应该运行的工作。这不是云功能的工作原理。函数旨在运行以响应项目中发生的事件。

相关问题