Skip to content

Instantly share code, notes, and snippets.

@richardkazuomiller
Created February 19, 2014 06:52
Show Gist options
  • Save richardkazuomiller/9087254 to your computer and use it in GitHub Desktop.
Save richardkazuomiller/9087254 to your computer and use it in GitHub Desktop.
node-http-proxy routing proxy with websockets
var httpProxy = require('http-proxy')
var proxy = httpProxy.createProxy({
ws : true
});
var options = {
'herp.dev': 'http://0.0.0.0:9008',
'derp.dev' : 'http://0.0.0.0:3000'
}
var server = require('http').createServer(function(req, res) {
proxy.web(req, res, {
target: options[req.headers.host]
},function(e){
log_error(e,req);
});
})
server.on('upgrade',function(req,res){
proxy.ws(req, res, {
target: options[req.headers.host]
},function(e){
log_error(e,req);
});
})
server.listen(80)
function log_error(e,req){
if(e){
console.error(e.message);
console.log(req.headers.host,'-->',options[req.headers.host]);
console.log('-----');
}
}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
@jasin
Copy link

jasin commented Jun 28, 2015

Thanks, this solved my proxy issue

@Nikhiladiga
Copy link

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment