2015-02-05 13:39:00 +01:00
|
|
|
var express = require('express'),
|
|
|
|
bodyParser = require('body-parser'),
|
|
|
|
cookieParser = require('cookie-parser'),
|
|
|
|
log4js = require('log4js'),
|
|
|
|
logger = require('./lib/logger'),
|
|
|
|
routes = require('./lib/routes'),
|
|
|
|
eventApi = require('./lib/eventApi'),
|
|
|
|
featureApi = require('./lib/featureApi'),
|
2014-12-17 21:56:27 +01:00
|
|
|
featureArchiveApi = require('./lib/featureArchiveApi'),
|
2015-02-05 13:39:00 +01:00
|
|
|
strategyApi = require('./lib/strategyApi'),
|
|
|
|
validator = require('express-validator'),
|
|
|
|
app = express(),
|
|
|
|
router = express.Router(),
|
|
|
|
baseUriPath = process.env.BASE_URI_PATH || '';
|
2014-12-03 15:22:03 +01:00
|
|
|
|
|
|
|
if(app.get('env') === 'development') {
|
|
|
|
app.use(require('errorhandler')());
|
|
|
|
|
|
|
|
var webpack = require('webpack'),
|
|
|
|
webpackDevMiddleware = require('webpack-dev-middleware'),
|
|
|
|
webpackConfig = require('./webpack.config'),
|
|
|
|
compiler = webpack(webpackConfig),
|
|
|
|
config = {
|
|
|
|
publicPath: '/js',
|
|
|
|
noInfo: true
|
|
|
|
};
|
|
|
|
|
|
|
|
app.use(baseUriPath, webpackDevMiddleware(compiler, config));
|
|
|
|
}
|
|
|
|
|
|
|
|
app.use(validator([]));
|
|
|
|
|
|
|
|
app.set('trust proxy');
|
|
|
|
app.locals.baseUriPath = baseUriPath;
|
|
|
|
|
2015-03-10 16:30:56 +01:00
|
|
|
app.use(log4js.connectLogger(logger, {
|
|
|
|
format: ':remote-addr :status :method :url :response-timems',
|
|
|
|
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
|
|
|
|
}));
|
|
|
|
|
2014-12-03 15:22:03 +01:00
|
|
|
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
|
|
|
|
|
|
|
|
app.use(baseUriPath, express.static(__dirname + '/public'));
|
|
|
|
app.use(bodyParser.json({strict: false}));
|
|
|
|
|
2015-02-05 13:39:00 +01:00
|
|
|
app.use(cookieParser());
|
|
|
|
|
2014-12-03 15:22:03 +01:00
|
|
|
eventApi(router);
|
|
|
|
featureApi(router);
|
2014-12-17 21:56:27 +01:00
|
|
|
featureArchiveApi(router);
|
2014-12-03 15:22:03 +01:00
|
|
|
strategyApi(router);
|
|
|
|
routes(router);
|
|
|
|
app.use(baseUriPath, router);
|
|
|
|
|
2015-02-05 13:39:00 +01:00
|
|
|
module.exports = app;
|