-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (61 loc) · 1.85 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
69
70
71
72
73
74
75
76
77
const express = require('express');
const session = require('express-session');
const app = express();
const config = require('config');
const path = require('path');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config();
const IN_PROD = process.env.NODE_ENV === 'production';
SESSION_LIFETIME = 1000 * 60 * 60 * 8; //8 Hours
app.use(
session({
name: process.env.SESSION_NAME,
resave: false,
saveUninitialized: false,
secret: process.env.SESSION_SECRET,
cookie: {
maxAge: SESSION_LIFETIME,
sameSite: true,
secure: IN_PROD,
filterParameter: JSON.stringify({}),
sortParameter: JSON.stringify({'date':-1}),
set_status: 0,
ascFlag: 0,
descFlag: 0
}
})
);
// connect to db
mongoose
.connect(process.env.DB_CONNECT, {
useUnifiedTopology: true,
useNewUrlParser: true,
useCreateIndex: true
})
.then(() => console.log('Now connected to MongoDB!'))
.catch(err => console.error(`Something went wrong ${err}`));
// set the view engine to ejs
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
// middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
const authCandidate = require('./routes/auth');
app.use('/api/candidate', authCandidate);
const updateCandidate = require('./routes/update');
app.use('/api/candidate', updateCandidate);
const autocompleteCandidate = require('./routes/autocomplete');
app.use('/api/candidate', autocompleteCandidate);
app.get('/', (req, res) => {
res.render('admin.ejs', { adError: '', adSuccess: '' });
});
// Start server to listen to the port
app.listen(config.get('server.port'), () => {
console.log(
`[Server running on ${config.get('server.host')}:${config.get(
'server.port'
)}]`
);
});