繁体   English   中英

Firebase 云 Function 未部署

[英]Firebase Cloud Function not deploying

我正在尝试部署我的第一个 function,但我卡住了,我不明白我的代码有什么问题。 这是我收到的错误

functions[sendNotifications(europe-west1)]: Deployment error. 
Function failed on loading user code. Error message: Error: please examine your function logs 
to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

即使在那个链接中,我也没有找到可以帮助我理解问题出在哪里,我做错了什么的东西。 我希望你们中的某个人可以帮助我,这是我的代码:

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

exports.sendNotifications = functions
.region('europe-west1')
.pubsub.schedule('every day 13:00').onRun(async context => {

async.waterfall([
    function(callback) {
        url = 'http://niksimoni.pythonanywhere.com/api/pulizie_domani';
        request(url, (error, response, body) => {
            if (!error && response.statusCode === 200) {
                const APIResponse = JSON.parse(body);
                callback(null, APIResponse.strade);
            }
            else {
                callback('Error parsing the data');
            }
        })
    },
    function(streets, callback) {
        for (var i = 0; i < streets.length; i++) {
            async.waterfall([
                function(callback) {
                    let street = streets[i];
                    url = 'http://niksimoni.pythonanywhere.com/api/data_pulizie?indirizzo=' + street;
                    request(url, (error, response, body) => {
                        if (!error && response.statusCode === 200) {
                            const APIResponse = JSON.parse(body);
                            var topic = street;
                            var message = {
                                data: {
                                    title: street,
                                    subtitle: 'Pulizia domani alle ' + APIResponse.ora,
                                },
                                topic: topic
                            };
                            admin.messaging().send(message)
                            .then((response) => {
                                // Response is a message ID string.
                                console.log('Successfully sent message:', response);
                            })
                            .catch((error) => {
                                console.log('Error sending message:', error);
                            });
                            callback(null, message);
                        } else {
                            callback('Error parsing the data');
                        }
                    })
                }
            ], function(error, results) {
                if (error) {
                    console.log(error.message);
                }
            });
        }
        callback(null);
    }
], function(error, results) {
    if (error) {
        console.log(error.message);
    } 
});
});

已解决,我必须将依赖项添加到 packages.json 文件中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM