-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (50 loc) · 1.63 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
//Require NPM Packages
const express = require('express'),
app = express(),
mustache = require('mustache-express'),
pgp = require('pg-promise')(),
methodOverride = require('method-override'),
session = require('express-session'),
bdPars = require('body-parser'),
morgan = require('morgan');
//configure express and related packages
app.engine('html', mustache());
app.set('view engine', 'html');
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.use(methodOverride('__method')); //method override
app.use(morgan('dev')); // Log All Requests
app.use(bdPars.urlencoded({
extended: false
})); //body parser
app.use(bdPars.json()); //body parser
app.use(session({
secret: 'quedj',
resave: false,
saveUninitialized: true,
cookie: {
secure: false
}
}));
const checkSession = require('./lib/helpers/checkSession');
//Redirects any user that is not logged in when visiting /users
app.all(['/users*','/queue*'], checkSession)
//Controllers
const USERS_ROUTER = require('./controllers/Users');
const SESSIONS_ROUTER = require('./controllers/Sessions');
const HOME_ROUTER = require('./controllers/Home');
const DASHBOARDS_ROUTER = require('./controllers/Dashboards');
const QUEUE_ROUTER = require('./controllers/Queue');
const API_ROUTER = require('./controllers/Api');
// Define All Routes
app.use(HOME_ROUTER);
app.use(SESSIONS_ROUTER);
app.use(DASHBOARDS_ROUTER);
app.use('/Users', USERS_ROUTER);
app.use('/Queue', QUEUE_ROUTER);
app.use('/Api', API_ROUTER);
//start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log('Server running on port ' + PORT + '!');
});