Created
July 4, 2014 14:09
-
-
Save alanhoff/46792f259b6091bd044b to your computer and use it in GitHub Desktop.
Proxy em Node.js puro
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 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