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');
|
2014-12-03 15:22:03 +01:00
|
|
|
|
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 || '';
|
2014-12-03 15:22:03 +01:00
|
|
|
|
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());
|
2014-12-03 15:22:03 +01:00
|
|
|
|
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
|
|
|
|
2016-05-01 22:53:09 +02:00
|
|
|
// Setup API routes
|
|
|
|
routes.create(router, config);
|
2016-05-01 18:20:10 +02:00
|
|
|
app.use(baseUriPath, router);
|
2014-12-03 15:22:03 +01:00
|
|
|
|
2016-05-01 18:20:10 +02:00
|
|
|
return app;
|
|
|
|
};
|