2014-10-20 13:03:43 +02:00
|
|
|
var express = require('express'),
|
|
|
|
bodyParser = require('body-parser'),
|
|
|
|
log4js = require('log4js'),
|
|
|
|
logger = require('./lib/logger'),
|
|
|
|
routes = require('./lib/routes'),
|
2014-10-24 15:32:33 +02:00
|
|
|
eventApi = require('./lib/eventApi'),
|
2014-10-24 15:14:15 +02:00
|
|
|
featureApi = require('./lib/featureApi'),
|
2014-10-30 21:10:48 +01:00
|
|
|
strategyApi = require('./lib/strategyApi'),
|
2014-10-20 13:03:43 +02:00
|
|
|
validator = require('express-validator'),
|
|
|
|
app = express(),
|
|
|
|
router = express.Router(),
|
|
|
|
baseUriPath = process.env.BASE_URI_PATH || '';
|
|
|
|
|
|
|
|
if(app.get('env') === 'development') {
|
|
|
|
app.use(require('errorhandler')());
|
2014-10-30 16:56:34 +01:00
|
|
|
|
|
|
|
var webpack = require('webpack'),
|
|
|
|
webpackDevMiddleware = require('webpack-dev-middleware'),
|
|
|
|
webpackConfig = require('./webpack.config'),
|
|
|
|
compiler = webpack(webpackConfig),
|
2014-10-31 10:30:23 +01:00
|
|
|
config = {
|
|
|
|
publicPath: '/js',
|
|
|
|
noInfo: true
|
|
|
|
};
|
2014-10-30 16:56:34 +01:00
|
|
|
|
|
|
|
app.use(baseUriPath, webpackDevMiddleware(compiler, config));
|
2014-10-20 13:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
app.use(validator([]));
|
|
|
|
|
|
|
|
app.set('trust proxy');
|
|
|
|
app.locals.baseUriPath = baseUriPath;
|
|
|
|
|
|
|
|
app.use(log4js.connectLogger(logger, {format: ':remote-addr :status :method :url :response-timems'}));
|
2014-11-06 21:26:55 +01:00
|
|
|
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
|
2014-10-20 13:03:43 +02:00
|
|
|
|
|
|
|
app.use(baseUriPath, express.static(__dirname + '/public'));
|
|
|
|
app.use(bodyParser.json({strict: false}));
|
|
|
|
|
2014-10-24 15:32:33 +02:00
|
|
|
eventApi(router);
|
2014-10-24 15:14:15 +02:00
|
|
|
featureApi(router);
|
2014-10-30 21:10:48 +01:00
|
|
|
strategyApi(router);
|
2014-10-20 13:03:43 +02:00
|
|
|
routes(router);
|
|
|
|
app.use(baseUriPath, router);
|
|
|
|
|
|
|
|
var server = app.listen(app.get('port'), function() {
|
|
|
|
logger.info('unleash started on ' + app.get('port'));
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('uncaughtException', function(err) {
|
|
|
|
logger.error('Uncaught Exception:', err.message);
|
|
|
|
logger.error(err.stack);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
app: app,
|
|
|
|
server: server
|
2014-11-06 21:26:55 +01:00
|
|
|
};
|