Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created April 19, 2014 13:26
Show Gist options
  • Select an option

  • Save adohe-zz/11084363 to your computer and use it in GitHub Desktop.

Select an option

Save adohe-zz/11084363 to your computer and use it in GitHub Desktop.
simple http proxy implementation in 15 lines of node.js code
var http = require('http');
http.createServer(function(req, res) {
var options = {
hostname: req.headers.host,
port: 80
};
var request = http.request(options, function(response) {
res.writeHead(response.statusCode, response.headers);
response.pipe(res);
});
req.pipe(request);
}).listen(8080, function() {
console.log('proxy server bind at http://localhost:8080/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment