-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
43 lines (36 loc) · 852 Bytes
/
server.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
const express = require('express');
const morgan = require('morgan');
const clientSession = require('client-sessions');
const helmet = require('helmet');
const nunjucks = require('nunjucks');
const {SESSION_SECRET} = require('./config');
const app = express();
const router = require('./src/router');
app.use(express.static('public'));
app.use(morgan('short'));
app.use(express.urlencoded({extended: false}));
nunjucks.configure('src/views', {
autoescape: true,
express: app
});
app.use(
clientSession({
cookieName: 'session',
secret: SESSION_SECRET,
duration: 24 * 60 * 60 * 1000
})
);
app.use(helmet());
app.use(router);
let server;
module.exports = {
start(port) {
server = app.listen(port, () => {
console.log(`App started on port ${port}`);
});
return app;
},
stop() {
server.close();
}
};