Skip to content

Instantly share code, notes, and snippets.

@ryanstevens
Created November 15, 2012 04:46
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 ryanstevens/4076718 to your computer and use it in GitHub Desktop.
Save ryanstevens/4076718 to your computer and use it in GitHub Desktop.
var proxyServer = httpProxy.createServer(function (req, res, proxy) {
//look for anything with "socket" in the sub-domain and route to node, otherwise route to php
var host = req.headers.host,
target = routes.getTarget([host]);
if (!target) {
logger.error("No route for " + host+", cannot serve "+req.url);
res.end();
return;
}
logger.info("Routing "+host+req.url+" to "+target.host+":"+target.port)
proxy.proxyRequest(req, res, {
host: target.host,
port: target.port
})
}).listen(props.get('ports:http'));
//only SSL terminate if its actually assigned to 443
if (props.get('ports:https') === 443) {
//terminate SSL and proxy
httpProxy.createServer(props.get('ports:http'), props.get('domain'), {
https: {
key: fs.readFileSync(__dirname + '/certs/'+props.get('certFile')+'.key', 'utf8'),
cert: fs.readFileSync(__dirname + '/certs/'+props.get('certFile')+'.crt', 'utf8')
}
}).listen(props.get('ports:https'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment