我已经从一个软件与rest api服务,我不想直接调用这个API,所以我已经添加了一个代理,使用NPM模块Rocky,我能够转发我的请求到我的API服务,但在响应中,我必须传递更多的参数(即操作我的响应),下面是我正在使用的代码片段。
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();
});但我无法拦截它。
发布于 2017-07-03 20:28:53
这可能会有帮助-
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();
});https://stackoverflow.com/questions/44885178
复制相似问题