Created
April 19, 2014 13:26
-
-
Save adohe-zz/11084363 to your computer and use it in GitHub Desktop.
simple http proxy implementation in 15 lines of node.js code
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'); | |
| 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