Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created November 11, 2012 21:49
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 shripadk/4056389 to your computer and use it in GitHub Desktop.
Save shripadk/4056389 to your computer and use it in GitHub Desktop.
var http = require('http');
var cp = require('child_process');
var httpProxy = require('http-proxy');
var sentinelChild = cp.spawn('node', ['app.js'], {stdio: 'inherit'});
var agentChild = cp.spawn('node', ['agent/agent.js'], {stdio: 'inherit'});
var agent = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 3002
}
});
var sentinel = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 3001
}
});
var server = httpProxy.createServer(function (req, res) {
if(req.url.match(new RegExp("^\/agent"))) {
agent.proxyRequest(req, res);
} else {
sentinel.proxyRequest(req, res);
}
});
server.on('upgrade', function(req, socket, head) {
if(req.url.match(new RegExp("^\/agent"))) {
agent.proxyWebSocketRequest(req, socket, head);
} else {
sentinel.proxyWebSocketRequest(req, socket, head);
}
});
server.listen(3000);
process.on('exit', function() {
sentinelChild.kill();
agentChild.kill();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment