donal
2018-04-26 9f311a49e45ae2999e2cf510cd16a8abb6a738bf
commit | author | age
6ef0cc 1 /**
D 2  * Express configuration
3  */
4
5 'use strict';
6
c382ab 7 const express = require('express');
D 8 const morgan = require('morgan');
9 const compression = require('compression');
10 const bodyParser = require('body-parser');
11 const methodOverride = require('method-override');
12 const cookieParser = require('cookie-parser');
13 const errorHandler = require('errorhandler');
14 const path = require('path');
15 const config = require('./environment');
6ef0cc 16
D 17 module.exports = function(app) {
c382ab 18   const env = app.get('env');
6ef0cc 19
D 20   app.set('views', config.root + '/server/views');
21   app.engine('html', require('ejs').renderFile);
22   app.set('view engine', 'html');
23   app.use(compression());
24   app.use(bodyParser.urlencoded({ extended: false }));
25   app.use(bodyParser.json());
26   app.use(methodOverride());
27   app.use(cookieParser());
9f311a 28   if ('production' === env  || 'dev' === env  || 'test' === env) {
D 29     // app.use(express.static(path.join(config.root, 'public')));
30     // app.set('appPath', path.join(config.root, 'public'));
6ef0cc 31     app.use(morgan('dev'));
D 32   }
33
34   if ('development' === env || 'test' === env) {
35     app.use(require('connect-livereload')());
36     app.use(express.static(path.join(config.root, '.tmp')));
37     app.use(express.static(path.join(config.root, 'client')));
38     app.set('appPath', path.join(config.root, 'client'));
39     app.use(morgan('dev'));
40     app.use(errorHandler()); // Error handler - has to be last
41   }
42 };