Skip to content

Instantly share code, notes, and snippets.

@comster
Forked from richardkazuomiller/proxy.js
Created November 9, 2015 05:38
Show Gist options
  • Save comster/424c3b2d7d761ac94d46 to your computer and use it in GitHub Desktop.
Save comster/424c3b2d7d761ac94d46 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 <[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