2015-09-04 01:26:56 -04:00
|
|
|
var compression = require('compression');
|
|
|
|
var express = require('express');
|
2015-09-30 11:04:51 -04:00
|
|
|
var proxy = require('express-http-proxy');
|
2015-09-14 13:36:00 -04:00
|
|
|
var _path = require('path');
|
2015-09-04 01:26:56 -04:00
|
|
|
|
|
|
|
var handler = require('./handler');
|
|
|
|
var log = require('./log');
|
|
|
|
var routes = require('./routes.json');
|
|
|
|
|
|
|
|
// Server setup
|
|
|
|
var app = express();
|
|
|
|
app.disable('x-powered-by');
|
|
|
|
app.use(log());
|
|
|
|
app.use(compression());
|
|
|
|
|
|
|
|
// Bind routes
|
2015-09-30 11:04:51 -04:00
|
|
|
for (var rId in routes) {
|
|
|
|
var route = routes[rId];
|
2015-09-14 12:16:58 -04:00
|
|
|
if ( route.static ) {
|
2015-09-14 13:17:50 -04:00
|
|
|
app.use( express.static( eval( route.resolve ), route.attributes ) );
|
2015-09-14 12:16:58 -04:00
|
|
|
} else {
|
2015-09-14 13:17:50 -04:00
|
|
|
app.get(route.pattern, handler(route));
|
2015-09-14 12:16:58 -04:00
|
|
|
}
|
2015-09-04 01:26:56 -04:00
|
|
|
}
|
|
|
|
|
2015-09-30 11:04:51 -04:00
|
|
|
// Bind proxies in development
|
|
|
|
if ( process.env.ENVIRONMENT == 'development' ) {
|
|
|
|
var proxies = require('./proxies.json');
|
|
|
|
var url = require('url');
|
|
|
|
for (var pId in proxies) {
|
|
|
|
var proxyRoute = proxies[pId];
|
|
|
|
app.use(proxyRoute.root, proxy(proxyRoute.proxy, {
|
|
|
|
filter: function (req) {
|
|
|
|
return proxyRoute.paths.indexOf(url.parse(req.url).path) > -1;
|
|
|
|
},
|
|
|
|
forwardPath: function (req) {
|
|
|
|
return url.parse(req.url).path;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 01:26:56 -04:00
|
|
|
// Start listening
|
2015-09-16 10:40:03 -04:00
|
|
|
var port = process.env.PORT || 8333;
|
2015-09-04 01:26:56 -04:00
|
|
|
app.listen(port, function () {
|
|
|
|
process.stdout.write('Server listening on port ' + port + '\n');
|
|
|
|
});
|