【发布时间】:2018-01-12 19:58:32
【问题描述】:
我正在尝试使用 Restify 创建一个 API,但我无法读取请求的正文。
这是代码
main.js:
'use strict';
const perfy = require('perfy');
perfy.start('startup');
const restify = require('restify');
const operation = require('./operation');
// post call for redirect
server.post('/test', operation.status);
操作.js:
'use strict';
module.exports =
{
/**
*
* @param {Object} req The request object as received from the middleware
* @param {Object} res The response object as received from the middleware
* @param {Function} next The next function to be called by the middleware
*/
status: function(req, res, next)
{
// Check configuration loading:
CONF.get()
.then( SETTINGS =>
{
req.log.debug('[TRACKER] The tracker has been requested to send the following data: %s', req.body);
// Then return 200 if everything is OK:
res.send(
{
status: 'OK!'
});
next();
})
.catch( err =>
{
// Return server error:
next(new restify.InternalError('Could not load configuration. ' + err));
});
}
};
在邮递员中,我在 POST 中调用服务:
然后,它接收到帖子(返回状态:ok)但记录器无法查看正文。未定义:
这是日志的结果: "[TRACKER] 已请求跟踪器发送以下数据:undefined","time":"2018-01-11T12:06:13.133Z","v":0}
我哪里做错了?
【问题讨论】:
标签: javascript node.js post server restify