Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created July 4, 2014 14:09
Show Gist options
  • Select an option

  • Save alanhoff/46792f259b6091bd044b to your computer and use it in GitHub Desktop.

Select an option

Save alanhoff/46792f259b6091bd044b to your computer and use it in GitHub Desktop.
Proxy em Node.js puro
var http = require('http');
// Criando o servidor para o proxy
http.Server(function(req, res){
var options = {
host : 'localhost',
port : 8081,
headers : req.headers,
method : req.method
};
var client = http.request(options, function(response){
res.writeHead(response.statusCode, response.headers);
response.pipe(res);
});
req.pipe(client);
}).listen(8080);
// Emulando o servior que será proxyado
http.Server(function(req, res){
res.write('Hello world');
res.end();
}).listen(8081);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment