So this is probably a very simple question, but I've been Googling around for over an hour and haven't been able to find anything. I also just tried printing out the request object, and I don't see anything useful.
How do I get the data or body of a client request within a grunt-contrib-connect middleware definition?
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;
}
}
}
}