【发布时间】:2018-12-06 16:01:00
【问题描述】:
在我代理到一个地址之前,我想设置代理的标头(Smth 就像一个拦截器)。我使用 express-http-library 并使用 Node.JS 表达。到目前为止,我的代码如下所示。顺便提一句。这个库的文档并没有让我变得更聪明。
app.use('/v1/*', proxy('velodrome.usefixie.com', {
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
// recieves an Object of headers, returns an Object of headers.
headers = {
Host: 'api.clashofclans.com',
'Proxy-Authorization': `Basic ${new Buffer('token').toString('base64')}`
};
console.log(headers);
return headers;
}
}));
即使控制台将我打印出标题 obj。正如预期的那样,代理授权不起作用:
{ Host: 'api.clashofclans.com',
'Proxy-Authorization': 'Basic token' }
谁能帮帮我?
【问题讨论】:
-
我提供的答案比已接受的答案更完整,即使在 3 年后的现在,它仍在继续获得支持...您能否将我的答案标记为已接受的答案?
标签: node.js http express proxy