使用npm的节点js中的响应拦截器rocky
问题描述:
我从其中一个软件中获得了其他api服务,我不想直接调用此API,因此我使用NPM模块Rocky添加了代理,我能够将我的请求转发给MY API SERVICE,但在响应中我必须传递更多参数(即操纵我的响应),下面的 是我正在使用的代码片段。使用npm的节点js中的响应拦截器rocky
JS
proxy
.post('/Authenticate/user')
.forward('http://192.168.1.200:8081/v1/')
.use((req, res, next) => {
if(req.params.name === 'admin') {
// Overwrite the target URL only for this user
console.log('Intercepted log');
}
next();
});
但我不能拦截它。
答
这可能帮助 -
proxy
.post('/Authenticate/user')
.forward('http://192.168.1.200:8081/v1/')
.use(function (req, res, next) {
if (req.params.name === 'admin') {
// Overwrite the target URL only for this user
console.log('Intercepted log');
// manipulate res here
}
next();
});
电话不。用块来{} –