-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (28 loc) · 1.03 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
const path = require('path');
const express = require('express');
const session = require('express-session');
const csrf = require('csurf');
const sessionConfig = require('./config/session');
const db = require('./data/database');
const authRoutes = require('./routes/auth');
const blogRoutes = require('./routes/blog');
const authMiddleware = require('./middlewares/auth-middleware');
const addCSRFTokenMiddleware = require('./middlewares/csrf-token-middleware');
const mongoDbSessionStore = sessionConfig.createSessionStore(session);
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static('public'));
app.use(express.urlencoded({ extended: false }));
app.use(session(sessionConfig.createSessionConfig(mongoDbSessionStore)));
app.use(csrf());
app.use(addCSRFTokenMiddleware);
app.use(authMiddleware);
app.use(authRoutes);
app.use(blogRoutes);
app.use(function (error, req, res, next) {
res.render('500');
});
db.connectToDatabase().then(function () {
app.listen(3000);
});