我正在尝试测试我通过faye从客户端发送的消息。
curl -X POST -H "Content-Type:application/json" -d '{"message":"Hi there."}' http://localhost:8000/message
这是culript系列。
TypeError: Cannot read property 'message' of undefined<br>
更新:culript实际上可能在这里......
app.post('/message', function(req, res) {
bayeux.getClient().publish('/channel', {text: req.body.message});
res.send(200);
});
不幸的是,我收到了这个错误。出于某种原因,它将消息视为未定义的属性,我不确定原因。
提前感谢您的帮助。
答案 0 :(得分:2)
您缺少必需的正文解析中间件,例如body-parser
的.json()
中间件。
安装该模块并添加
var bodyParser = require('body-parser');
app.use(bodyParser.json());
在路线前的某个地方。