【问题标题】:Firebase function says deployed but won't show up in Firebase ConsoleFirebase 功能说已部署,但不会显示在 Firebase 控制台中
【发布时间】:2019-07-04 14:34:17
【问题描述】:

我正在尝试向我的应用程序添加通知功能,以便一旦用户发布帖子,任何订阅他们的人都会收到通知。目前我正在尝试编写一个云函数来实现这一点。

但是,编写一个小测试未能部署到我的项目中。

注意:如果有人有关于如何为 Flutter 完成类似操作的链接,我们将不胜感激。

我查看了我能找到的几个示例,趋势是 js 代码有问题,但我看不到任何示例。

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

exports.sendNotification = 
functions.firestore.document('Orders/{resturantId}/Orders')
.onWrite((change, context) =>{

const notificationContent = {
            notification:{
                title: "/*App name */",
                body: "You have a new Comment!",
                icon: "default",
                click_action: "/*Package */_TARGET_NOTIFICATION"
        }
    };

    return admin.messaging().sendToTopic("-LV_05ip0wf1dFEg45wx", notificationContent)
    .then(result => {
        console.log("Notification sent!");
        return;
    });
});

【问题讨论】:

  • 请编辑问题以显示firebase deploy 的整个输出,确认该功能已部署。
  • 看起来您的 .js 文件放错了位置,或者您在路径的错误部分运行了 firebase cli - 请仔细检查这些内容...
  • 您能详细说明一下吗?检查路径它表明我有一个 index.js 里面

标签: javascript firebase flutter google-cloud-firestore google-cloud-functions


【解决方案1】:

由于对环境不熟悉,我没有意识到我在初始化 firebase 函数时选择了类型脚本。所以我应该使用 index.ts 而不是 index.js。

此外,正确的函数部署实际上是这样的。

【讨论】:

    猜你喜欢
    • 2018-08-07
    • 2017-12-01
    • 2020-09-29
    • 1970-01-01
    • 2021-06-15
    • 2021-07-16
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多