所以这可能是一个非常简单的问题,但我已经在谷歌上搜索了一个多小时,但什么也没找到。我也只是尝试打印出请求对象,但没有看到任何有用的东西。
如何在 grunt-contrib-connect 中间件定义中获取客户端请求的数据或正文?
connect: {
main: {
options: {
hostname: "0.0.0.0",
port: 8080,
/**
* These are the mocked out backends for various endpoints
*/
middleware: function(connect, options, middlewares) {
middlewares.unshift(function(req, res, next) {
if (req.url !== '/v1/accounts/_findEmail') {
return next();
}
// ********
// How do I get the data content of the request?
var data = req.data; // Is undefined
// ********
if (data && data.email === 'taken@email.com') {
res.writeHead(200, {"Content-Type": "application/json"});
res.write(JSON.stringify({email:"found"}));
} else {
res.writeHead(404, {"Content-Type": "application/json"});
res.write(JSON.stringify({email:"not found"}));
}
res.end();
});
return middlewares;
}
}
}
}