我正在尝试使用路由器表创建一个NodeJS http代理.我看到一些使用http-proxy的例子并尝试这样:
var httpProxy = require('http-proxy');
var proxyTable = {};
proxyTable['testproxy.com/toto'] = 'google.com:80';
proxyTable['testproxy.com/tata'] = 'gmail.com:80';
var httpOptions = {
router: proxyTable
};
console.log('Proxy Server Listening on port 80');
console.log('Requests to textproxy.com/toto (on port 80) are redirected to google.com:80');
console.log('Requests to textproxy.com/tata (on port 80) are redirected to gmail.com:80');
httpProxy.createServer(httpOptions).listen(80);
Run Code Online (Sandbox Code Playgroud)
仅供参考:testproxy.com参考127.0.0.1.
它似乎工作(它只拦截testproxy.com/toto和tata的请求),但当我尝试:
curl http://testproxy.com/toto
Run Code Online (Sandbox Code Playgroud)
我有一个NodeJS错误:
var proxyReq = (options.target.protocol === 'https:' ? https : http).reque
^
TypeError: Cannot read property 'protocol' of undefined
at Array.stream [as 3] (D:\workspace\Proxy W_S\node_modules\http-proxy\l
ib\http-proxy\passes\web-incoming.js:103:35) …Run Code Online (Sandbox Code Playgroud)