-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (47 loc) · 1.76 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
"use strict";
const express = require('express');
const compression = require('compression');
const helmet = require('helmet');
const path = require('path');
const cookieParser = require('cookie-parser');
const initializeDatabases = require('./db');
const system = require('./system/controller');
const errorHandler = require('./system/errorHandler');
const index = require('./routes/index');
const config = require('./config/config.json');
const lang = require('./config/language/' + config.general.defaultLanguage + '.json');
const app = express();
const port = config.general.port;
// View engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// Use gzip compression and security patch
app.use(compression());
app.use(helmet());
// Initialize public directory
app.use(express.static(path.join(__dirname, 'public')));
// Support parsing of application/json type post data
app.use(express.json());
// Support parsing of application/x-www-form-urlencoded post data
app.use(express.urlencoded({ extended: true }));
// Support cookie parsing
app.use(cookieParser());
const startApp = async () => {
// Initialize databases
const dbs = await initializeDatabases().catch((err) => {
console.error('Failed to make all database connections!');
console.error(err);
process.exit(1);
});
// Setup controller
const controller = await system(config, lang, dbs);
// Initialize routes
app.use('/', index(controller));
app.listen(port, () => {
console.log('App running on port ' + port);
});
// Initialize error handler
app.use(errorHandler.catch404(lang));
app.use(errorHandler.initialize(controller));
}
startApp();