Skip to content

Instantly share code, notes, and snippets.

@bhurlow
Created May 7, 2013 19:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhurlow/5535282 to your computer and use it in GitHub Desktop.
Save bhurlow/5535282 to your computer and use it in GitHub Desktop.
minimalistic node http proxy
var http = require('http');
var url = require('url');
var path = require('path');
var request = require('request');
var ports = {
"localhost": 3100,
"dev.localhost": 3200
}
var proxyServer = http.createServer(proxy).listen(3000)
function proxy(req, res) {
var fromUrl = 'http://' + req.headers.host
var hostname = url.parse(fromUrl).hostname
var uri = 'http://' + hostname + ':' + ports[hostname]
request(uri).pipe(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment