Skip to content

Instantly share code, notes, and snippets.

@nodesocket
Created November 26, 2011 21:52
Show Gist options
  • Save nodesocket/1396354 to your computer and use it in GitHub Desktop.
Save nodesocket/1396354 to your computer and use it in GitHub Desktop.
Bounce With Re-Writes
//Assume this structure storing routes and corresponding host and port
var routes = [ '/app1': { host: '127.0.0.1', port: 3000 },
'/app2': { host: '127.0.0.1', port: 3010 },
'/app3': { host: '127.0.0.1', port: 3020 } ];
http_proxy(function (req, bounce) {
var route = routes[req.url];
if(typeof route === "object") {
//Want to rewrite the url, remove '/app1' or basically the key in the array structure
bounce(route.host, route.port);
}
}).listen(80);
////
// Ex:
////
// Request: /app1/create
// Should be re-wrote to: /create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment