0
라우터 테이블을 사용하여 NodeJS http-proxy를 만들려고합니다. 이 같은 HTTP 프록시 시도하여 몇 가지 예 보았다 : 참고로NodeJS 프록시 라우터 테이블
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 타타에 그것은 단지 차단 요청)을 작동하는 것 같다하지만 난 때:
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 프록시 모듈에서 이미 지원됩니까? 나는 동적 프록시를해야 하나?
저는 NodeJS에서 새 소식을 들었습니다. 답변 해 주셔서 감사합니다.
피에르 - 뤽
감사 요새 대답 예상 꾼 :
그러나, 그들은 새로운 API를 사용하여 수행하는 새로운 방법을 제공! Unfortunnatelly, 그것은 제거 될 것으로 보인다. somme 이유 (나는 기업의 배후에있다.) 나는 최종적으로 파이프와 함께 간단한 '요청'모듈을 사용한다. 그것은 매력처럼 작동합니다! 고마워 요새 to Eutard! –