Skip to content

Instantly share code, notes, and snippets.

@jrolfs
Created April 24, 2012 02:22
Show Gist options
  • Save jrolfs/2475547 to your computer and use it in GitHub Desktop.
Save jrolfs/2475547 to your computer and use it in GitHub Desktop.
Node.js, Express, node-http-proxy development server
var express = require('express'),
routingProxy = require('http-proxy').RoutingProxy(),
app = express.createServer();
var apiVersion = 1.0,
apiHost = my.host.com,
apiPort = 8080;
function apiProxy(pattern, host, port) {
return function(req, res, next) {
if (req.url.match(pattern)) {
routingProxy.proxyRequest(req, res, {host: host, port: port});
} else {
next();
}
}
}
app.configure(function () {
// API proxy middleware
app.use(apiProxy(new RegExp('\/' + apiVersion + '\/.*'), apiHost, apiPort));
// Static content middleware
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(express.static(__dirname));
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
app.use(app.router);
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment