node.js - "InvalidServerResponse"在向 NodeJS 应用程序发送请求期间

标签 node.js firebase google-cloud-firestore postman

我是 NodeJS 新手。 当我将 post 请求从 postman 发送到我的 Nodejs 应用程序时,我在控制台中收到了此消息。

应用程序正在监听端口:9000 无效服务器响应

代码:

var express = require('express');
var app = express();
var moment = require('moment');
var _ = require('underscore');
var fs = require('fs');
var HttpStatus = require('http-status');
var FCM = require('fcm-push');
var serverKey ="rTQq8LvUIFSbcG_6A....................";
var fcm = new FCM(serverKey);

var status = {
SUCCESS : 'success',
FAILURE : 'failure'
}

var httpStatus = {
OK : HttpStatus.OK,
ISE : HttpStatus.INTERNAL_SERVER_ERROR,
BR : HttpStatus.BAD_REQUEST
}
exports.likes= function(req, res){

var Username =req.body.username;
var likecount =req.body.count;
var likedby = req.body.likedby;
var postId = req.body.postId;
var tokenId = req.body.tokenId;
var message = {
                     to: tokenId, 
                     collapse_key: '',
                     data: {
                        name:Username,
                        Message:"Content about message",
                        Redirect:"TopostId : "+postId,
                        time: ""
                      },
                     notification: {
                                    title: "Hey Buddy , Someone have liked your post",
                                    body: likedby +"Likedyourpost",
                                    icon: "notification"
                                    }
                };


fcm.send(message)
    .then(function (response) {
        console.log("Successfully sent with response: ", response);
        res.status(httpStatus.OK).json({
        status: status.SUCCESS,
        code: httpStatus.OK,            
        error:''
    });
            return;
            })
        .catch(function (err) {
             console.log(err);

            });

};

我正在使用 Firebase 云消息发送推送通知。

最佳答案

我对“fcm-node”也有同样的问题。我用“fcm-notification”替换了该软件包,它对我来说工作正常。

关于node.js - "InvalidServerResponse"在向 NodeJS 应用程序发送请求期间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51061915/

相关文章:

Node.js 中的 JavaScript 作用域

javascript - 以 Mysql 格式在 Node js 中获取与今​​天日期相比的前一周日期

java - 如果使用 ChildEventListener 如何检查快照是否存在?

node.js - 如何在 Firestore 中进行时间戳查询

ios - AddSnapShotListener 在一个实例中重复读取文档

node.js - 并发访问共享数组是 Node.js 中的一个问题

javascript - 使用 node.js 编辑和创建 HTML 内容

firebase - 测试数据库模式下Firestore权限错误

java - DataSnapshot.getValue() 未正确检索对象

angular - 更新 firestore 数据后显示重复事件,但 firestore 中的数据本身不重复