我有一个NodeJs应用程序,正在用作we应用程序的服务器。 NodeJs处理我对Firebase实时数据库的数据库调用。当我使用localhost测试所有内容时,一切工作正常,但是当我将NodeJ(服务器)部署到Heroku时,我似乎缺少了一些东西。
我尝试执行从Web应用到NodeJs服务器的Post请求,服务器接收到该请求,但会引发以下错误
(node:21) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
2018-09-22T01:08:56.888825+00:00 app[web.1]: at createError (/app/node_modules/axios/lib/core/createError.js:16:15)
2018-09-22T01:08:56.888827+00:00 app[web.1]: at settle (/app/node_modules/axios/lib/core/settle.js:18:12)
2018-09-22T01:08:56.888831+00:00 app[web.1]: at emitNone (events.js:111:20)
2018-09-22T01:08:56.888829+00:00 app[web.1]: at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:201:11)
2018-09-22T01:08:56.888833+00:00 app[web.1]: at IncomingMessage.emit (events.js:208:7)
2018-09-22T01:08:56.888835+00:00 app[web.1]: at endReadableNT (_stream_readable.js:1064:12)
2018-09-22T01:08:56.888836+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:138:11)
2018-09-22T01:08:56.888842+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:180:9)
我的帖子请求:
axios.post('http://checkmeinserver.herokuapp.com/getlivecodes',
{
userId:currentUserID,
}).then((response)=>{ console.log(response)})
我的服务器代码正在监听发布请求:
app.post('/getlivecodes', (req, res) =>
var userId = req.body.userId;
var codesList = [];
var listLenght;
var count = 0;
//this gets printed correctly showing that the //server received the request and
console.log("Received request to retrieve live codes for user Id : "+userId)
ref.child('Companies').child(userId).child('LiveCodes').once('value').then(function(Datasnapshot)
{
})