Created
February 19, 2014 06:52
-
-
Save richardkazuomiller/9087254 to your computer and use it in GitHub Desktop.
node-http-proxy routing proxy with websockets
This file contains 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 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('-----'); | |
} | |
} |
This file contains 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <[email protected]> | |
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this solved my proxy issue