이것은 매우 간단한 질문 일 뿐이지 만 한 시간 이상 인터넷 검색을 해본 결과 아무 것도 찾을 수 없었습니다. 나는 또한 요청 객체를 인쇄 해 보았고, 유용한 것을 보지 못했다.grunt-contrib-connect 요청 개체에서 데이터 가져 오기
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 === '[email protected]') {
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;
}
}
}
}
게시 해 주셔서 감사합니다. 시간을 절약 해 줬어! Btw, 그것은 나를 위해 일했다 req.setEncoding ('utf8'); –