Created
April 9, 2014 14:11
-
-
Save fdabl/10275101 to your computer and use it in GitHub Desktop.
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 sys = require('sys'); | |
var http = require('http'); | |
function log(options) { | |
var info = [options.method, options.path].join(' '); | |
sys.log(info); | |
} | |
function proxy(options, req, res) { | |
return http.request(options, function(proxy_res) { | |
res.writeHead(proxy_res.statusCode, proxy_res.headers); | |
proxy_res.pipe(res); | |
}); | |
} | |
function handler(req, res) { | |
var options = { | |
port: 80, | |
path: req.url, | |
method: req.method, | |
hostname: req.headers.host | |
}; | |
log(options); | |
var proxied = proxy(options, req, res); | |
req.pipe(proxied); | |
} | |
http.createServer(handler).listen(4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment