0
내 브라우저에서 사용할 node.js와 함께 프록시를 만들고 싶습니다. Google에서 검색 한 결과 example이지만 일부 Api는 사용되지 않습니다. 노드 JS가있는 서버 프록시
그래서 나는 다음과 같은 코드 변경 : 3333 : 그 후var http = require('http');
http.createServer(function(request, response) {
console.log("req for:"+ request.headers['host'] + "\nmethod: "+ request.method);
var options = {
host : request.headers['host'],
method : request.method,
headers : request.headers
}
var callback = function(res){
// get the proxyclient response and write to the original response
res.addListener('data', function(chunk){
console.log("writing response");
response.write(chunk, 'binary');
});
res.addListener('end', function(){
console.log("end response");
response.end();
});
};
// send the original request
var proxy = http.request(options, callback);
// intercept the request and write to proxyclient
request.addListener('data', function(chunk){
console.log("new request");
proxy.write(chunk, 'binary');
});
request.addListener('end', function(){
console.log("end request");
proxy.end();
});
}).listen(3333);
을, 나는 로컬 호스트를 사용하는 브라우저의 프록시 설정을 변경했습니다. 제 문제는 "데이터"이벤트가 발생하지 않는다는 것입니다.
내가 생각한대로 작동해야합니까?
콜백 이벤트를 언급하고 있습니까? – NickSuperb
둘 다 '데이터'수신기 용 콘솔에 로그가 없습니다. – patricK