Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Created May 9, 2015 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazy4groovy/ee228c45658816958a64 to your computer and use it in GitHub Desktop.
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).
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