1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/app.js
2016-06-16 14:27:23 +02:00

52 lines
1.5 KiB
JavaScript

var express = require('express');
var favicon = require('serve-favicon');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var log4js = require('log4js');
var logger = require('./lib/logger');
var routes = require('./lib/routes');
var validator = require('express-validator');
var app = express();
var router = express.Router(); // eslint-disable-line
var baseUriPath = process.env.BASE_URI_PATH || '';
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(favicon(__dirname + '/public/favicon.ico'));
app.use(validator([]));
app.set('trust proxy');
app.locals.baseUriPath = baseUriPath;
app.use(log4js.connectLogger(logger, {
format: ':remote-addr :status :method :url :response-timems',
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
}));
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
app.use(baseUriPath, express.static(__dirname + '/public'));
app.use(bodyParser.json({ strict: false }));
app.use(cookieParser());
routes.create(router);
app.use(baseUriPath, router);
module.exports = app;