-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp.js
68 lines (52 loc) · 1.58 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var __root = __dirname;
var __config = __root + '/config/config.json';
var __static = __root + '/static';
var __src = __root + '/src';
var __views = __src + '/views';
var __js = __src + '/js';
var log = require( __js + '/logging' ).log;
log.info( {
app: 'main',
action: 'start'
} );
var config = require( __config );
var database = require( __js + '/database' ).connect( config.mongo );
var express = require( 'express' ),
helmet = require( 'helmet' ),
flash = require( 'express-flash' ),
app = express(),
http = require( 'http' ).Server( app );
var Options = require( __js + '/options' )();
app.use( Options.load );
var app_loader = require( __js + '/app-loader' );
// Add logging capabilities
require( __js + '/logging' ).installMiddleware( app );
// Use helmet
app.use( helmet() );
// Handle authentication
require( __js + '/authentication' ).auth( app );
// Setup static route
app.use( express.static( __static ) );
// Handle sessions
require( __js + '/sessions' )( app );
// Include support for notifications
app.use( flash() );
app.use( require( __js + '/quickflash' ) );
// Use PUG to render pages
app.set( 'views', __views );
app.set( 'view engine', 'pug' );
app.set( 'view cache', false );
// Set reverse proxy trust (see http://expressjs.com/en/guide/behind-proxies.html)
// default to false
app.set( 'trust proxy', config.reverseProxyTrust || false )
// Load apps
app_loader( app );
// Start server
var listener = app.listen( config.port ,config.host, function () {
log.debug( {
app: 'main',
action: 'start-webserver',
message: 'Started',
address: listener.address()
} );
} );