Created
February 21, 2011 04:36
-
-
Save joelklabo/836664 to your computer and use it in GitHub Desktop.
proxy server givin ECONNREFUSED error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http') | |
; | |
http.createServer( function (req, res) { | |
var client | |
, proxy_request | |
; | |
console.log('connection made - + ='); | |
switch (req.headers.host) { | |
case 'joelklabo.com': | |
client = http.createClient(8001, 'joelklabo.com') | |
console.log('connected from: ' + req.headers.host) | |
break; | |
case 'brooski.net': | |
client = http.createClient(8002, 'brooski.net') | |
console.log('connected from: ' + req.headers.host) | |
break; | |
} | |
proxy_request = client.request(req.method, req.url, req.headers) | |
proxy_request.addListener('response', function (response) { | |
response.addListener('data', function (chunk) { | |
res.write(chunk, 'binary') | |
}) | |
response.addListener('end', function () { | |
res.end() | |
}) | |
res.writeHead(response.statusCode, response.headers) | |
}) | |
req.addListener('data', function (chunk) { | |
proxy_request.write(chunk, 'binary') | |
}) | |
req.addListener('end', function (end) { | |
proxy_request.end() | |
}) | |
}).listen(80,'74.207.244.145') | |
console.log('Server is listening...') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment