Skip to content

Instantly share code, notes, and snippets.

@richorama
Created June 5, 2014 18:40
Show Gist options
  • Save richorama/28cfbd5add58dc0eea02 to your computer and use it in GitHub Desktop.
Save richorama/28cfbd5add58dc0eea02 to your computer and use it in GitHub Desktop.
An HTTP proxy server written in Node.js
var http = require('http');
var url = require('url');
http.createServer(function(request, response) {
console.log(request.url);
var options = url.parse(request.url);
options.method = request.method;
options.headers = request.headers;
var req = http.request(options, function(res){
response.writeHead(res.statusCode, res.headers);
res.pipe(response);
})
request.pipe(req);
}).listen(process.env.port || 8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment