Created
May 9, 2015 21:23
-
-
Save crazy4groovy/ee228c45658816958a64 to your computer and use it in GitHub Desktop.
A simple NodeJS service that returns whatever URI resource comes after its own domain name (ala proxy).
This file contains 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'), | |
request = require('request'); | |
http.createServer(function (req, resp) { | |
while (req.url.indexOf('/') === 0) | |
req.url = req.url.substring(1); | |
var opts = {url: decodeURIComponent(req.url), timeout: 3000} | |
try { | |
request(opts) | |
.on('error', function(err) {console.log('pipe error: ' + err); resp.end(err+'')}) | |
.pipe(resp); | |
} catch (err) { | |
console.log(err); | |
} | |
}).listen(process.env.PORT || 5000); | |
console.log('Server running at http://127.0.0.1:' + (process.env.PORT || 5000) + '/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment