forked from yaghouti/ticketing-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (46 loc) · 1.51 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
const fs = require('fs');
const express = require('express');
let bodyParser = require('body-parser');
let logger = require('morgan');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
const config = require('./configs')();
const redis = require('./configs/redis');
const app = express();
start();
async function start() {
app.use(logger('dev'));
app.use(bodyParser.json({limit: '10mb'}));
app.use(bodyParser.urlencoded({extended: true, limit: '10mb'}));
app.use(express.static(__dirname + '/views'));
app.use(session({
secret: config.session.secret,
resave: config.session.resave,
saveUninitialized: config.session.saveUninitialized,
store: new RedisStore({
host: config.redis.host,
port: config.redis.port,
client: redis.getRedisClient(config.session.redisDb),
ttl: config.session.ttl
})
}));
await loadRoutes();
app.listen(config.server.port, () => console.log(`Ticketing System app listening on port ${config.server.port}!`));
}
function loadRoutes() {
return new Promise(function (resolve, reject) {
fs.readdir('./controllers', function (error, files) {
if (error) {
console.log('Error while loading routes!');
reject(error);
}
files.forEach(function (file) {
let routesList = require('./controllers/' + file);
routesList.forEach(function (routeObj) {
app[routeObj.method](routeObj.route, routeObj.controller);
});
});
resolve();
});
})
}