Skip to content

Instantly share code, notes, and snippets.

@fdabl
Created April 9, 2014 14:11
Show Gist options
  • Save fdabl/10275101 to your computer and use it in GitHub Desktop.
Save fdabl/10275101 to your computer and use it in GitHub Desktop.
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