1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/app.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-04-30 23:41:09 +02:00
var express = require('express');
2016-05-01 15:43:25 +02:00
var favicon = require('serve-favicon');
2016-04-30 23:41:09 +02:00
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
2016-05-01 18:20:10 +02:00
var validator = require('express-validator');
2016-04-30 23:41:09 +02:00
var log4js = require('log4js');
var logger = require('./lib/logger');
var routes = require('./lib/routes');
2016-05-01 18:20:10 +02:00
module.exports = function(config) {
var app = express();
var router = express.Router(); // eslint-disable-line
var baseUriPath = config.baseUriPath || '';
2016-05-01 18:20:10 +02:00
app.set('trust proxy');
2016-05-01 22:59:43 +02:00
app.set('port', config.port);
2016-05-01 18:20:10 +02:00
app.locals.baseUriPath = baseUriPath;
2016-05-01 22:59:43 +02:00
app.use(cookieParser());
2016-05-01 22:59:43 +02:00
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(validator([]));
app.use(baseUriPath, express.static(__dirname + '/public'));
app.use(bodyParser.json({ strict: false }));
2016-05-01 18:20:10 +02:00
app.use(log4js.connectLogger(logger, {
format: ':remote-addr :status :method :url :response-timems',
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
}));
2015-03-10 16:30:56 +01:00
// Setup API routes
routes.create(router, config);
2016-05-01 18:20:10 +02:00
app.use(baseUriPath, router);
2016-05-01 18:20:10 +02:00
return app;
};