This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (50 loc) · 1.49 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
const expressSanitizer = require('express-sanitizer'),
methodOverride = require('method-override'),
RateLimit = require('express-rate-limit'),
createError = require('http-errors'),
bodyParser = require('body-parser'),
express = require('express'),
app = express();
const indexRoute = require('./routes/index'),
blogsRoute = require('./routes/blogs/blogs'),
authRoute = require('./routes/admin/auth'),
adminRoute = require('./routes/admin/admin');
const keys = require('./config/keys'),
passport = require('./services/passport');
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
app.use(
bodyParser.urlencoded({
extended: true
}));
app.use(expressSanitizer());
app.use(methodOverride('_method'));
app.use(new RateLimit({
windowMs: 1 * 60 * 1000,
max: 20
}));
app.use(
require('cookie-session')({
keys: [keys.session_secret],
maxAge: 30 * 24 * 60 * 60 * 1000
}));
app.use(passport.initialize());
app.use(passport.session());
app.use((req, res, next) => {
res.locals.currentUser = req.user;
next();
});
app.use(indexRoute);
app.use(blogsRoute);
app.use(authRoute);
app.use(adminRoute);
app.use(function (req, res, next) {
next(createError(404));
});
app.use(function (err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.render('error');
});
module.exports = app;