【问题标题】:NodeJS Proxy Router TableNodeJS 代理路由器表
【发布时间】:2014-02-11 11:37:43
【问题描述】:

我正在尝试使用路由器表制作 NodeJS http-proxy。 我看到了一些使用 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);

仅供参考:testproxy.com 参考 127.0.0.1。

它似乎有效(它只拦截对 testproxy.com/toto 和 tata 的请求)但是当我尝试时:

curl http://testproxy.com/toto

我有一个 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)
    at ProxyServer.<anonymous> (D:\workspace\Proxy W_S\node_modules\http-pro
xy\lib\http-proxy\index.js:83:21)
    at Server.closure (D:\workspace\Proxy W_S\node_modules\http-proxy\lib\ht
tp-proxy\index.js:125:43)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2108:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23
)
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:525:27)

http-proxy 模块是否已经支持路由表? 我必须做一个动态代理,知道吗?

我是 NodeJS 的新手,我被困住了。 非常感谢您的回答。

皮埃尔-吕克

【问题讨论】:

    标签: node.js proxy routing router http-proxy


    【解决方案1】:

    在发布 1.0.0 版时,似乎从 node-http-proxy 中删除了代理表路由。

    但是,他们提供了一种使用新 API 的新方法:

    https://blog.nodejitsu.com/node-http-proxy-1dot0/

    【讨论】:

    • 谢谢大家的回答!不幸的是,它似乎被删除了。出于某种原因(我支持公司代理),我最终将简单的“请求”模块与管道一起使用。它就像一个魅力!感谢 fort tout 帮助爱德华!
    猜你喜欢
    • 1970-01-01
    • 2014-04-14
    • 2023-04-07
    • 2018-09-27
    • 2017-03-29
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多