我想重定向用户请求,以便调用其他服务:
处理该api的响应。 对于标题,下面的代码运行良好,但我不能让它适用于body参数,我使用bodyParse和in / test函数我有整个初始请求localhost:8080 / test
app.all('/test', function (req, res) {
//req.body all parameters set for the initial request localhost:8080/test
var options = {
url: 'http://localhost:3000/api/user/isAuthenticated',
method: req.method,
headers: req.headers,
form: {
body:JSON.stringify(req.body)
}
};
request.post(options, function (err, httpResponse, body) {
//body undefinded if i use form: { body:JSON.stringify(req.body) }
//The body is passed i have something like {"body":"{\"email\":\" ... when i do req.body in the api controller but not the right format and with the key body so i need to do something like req.body.body in the api controller
//but work if i do not pass the body and delete form: { body:JSON.stringify(req.body) } i have the response of my api in the body variable below
console.log("CONSTOLE " + body)
if (body["authenticated"] == true) {
return res.json(body)
} else {
return res.json(body)
}
});
});
有没有办法传递请求的所有参数直接调用另一个api。