I am very new to nodejs, and I am using restify to create routes, and one of the routes, I call another API, whose response I want to send back.
我是nodejs的新手,我正在使用restify创建路由,其中一条路由,我称之为另一个API,我希望将其回复。
server.get({path:'/admin'},
function respond(req, res, next){
var options = { method: 'GET',
url: argv.OKTA + "/api/v1/apps/" + argv.OKTA_APP_ID,
headers:
{ authorization: argv.OKTA_API,
'content-type': 'application/json',
accept: 'application/json' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
res.send(200, body);
return next();
});
});
So, if a GET is done on the /admin path, it should go and call another URL, and get the response back and use that as a response back to the /admin
因此,如果在/ admin路径上完成了GET,它应该去调用另一个URL,然后获取响应,并将其作为响应返回给/ admin
Right now, I get this instead:
现在,我得到了这个:
{"code":"ResourceNotFound","message":"/admin does not exist"}
1 个解决方案
#1
0
Since you're sending a response, you should not call next()
(that calls the next middleware, which will end up at your 404 middleware).
由于您正在发送响应,因此不应调用next()(调用下一个中间件,最终将在您的404中间件中)。
#1
0
Since you're sending a response, you should not call next()
(that calls the next middleware, which will end up at your 404 middleware).
由于您正在发送响应,因此不应调用next()(调用下一个中间件,最终将在您的404中间件中)。