-
-
Save SeptiyanAndika/ef228928bddfda97a9aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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