Created
May 7, 2013 19:12
-
-
Save bhurlow/5535282 to your computer and use it in GitHub Desktop.
minimalistic node http proxy
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'); | |
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