-
-
Save jagtesh/1255762 to your computer and use it in GitHub Desktop.
This file contains 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'); | |
var url = require('url'); | |
http.createServer(function (req1, res1) { | |
var tmp = url.parse(req1.url); | |
var options = { | |
"host": tmp.hostname, | |
"port": tmp.port || 80, | |
"path": tmp.pathname + (tmp.search ? tmp.search : ''), | |
"method": req1.method, | |
"headers": req1.headers | |
}; | |
var req2 = http.request(options, function (res2) { | |
res1.writeHead(res2.statusCode, res2.headers); | |
res2.on('data', function (chunk) { | |
res1.write(chunk); | |
}); | |
res2.on('end', function () { | |
res1.end(); | |
}); | |
}); | |
req1.on('data', function (chunk) { | |
req2.write(chunk); | |
}); | |
req1.on('end', function () { | |
console.log(req1.method + " " + req1.url); | |
req2.end(); | |
}); | |
}).listen(8081); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment