我是nodeJS的新手。 从邮递员向我的nodejs应用程序发送发帖请求时,我在控制台中收到了此消息。
应用正在侦听以下端口:9000 InvalidServerResponse
代码:
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 Cloud Messaging发送推送通知。
答案 0 :(得分:1)
“ fcm-node”存在相同的问题。我用'fcm-notification'替换了软件包。