-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (36 loc) · 1.22 KB
/
app.js
File metadata and controls
47 lines (36 loc) · 1.22 KB
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
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const blogRouter = require('./routes/blogRoutes');
const viewRouter = require('./routes/viewRoutes');
const userRouter = require('./routes/userRoutes');
const cookieParcer = require('cookie-parser');
const helmet = require('helmet');
const xss = require('xss-clean');
const app = express();
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, `public`)));
app.use(helmet());
app.use(
helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'", 'https:', 'http:', 'data:', 'ws:'],
baseUri: ["'self'"],
fontSrc: ["'self'", 'https:', 'http:', 'data:'],
scriptSrc: ["'self'", 'https:', 'http:', 'blob:'],
styleSrc: ["'self'", "'unsafe-inline'", 'https:', 'http:'],
},
})
);
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
app.use(cookieParcer());
app.use(xss());
app.use(express.json({ limit: '10kb' }));
app.use(express.urlencoded({ extended: true, limit: '10kb' }));
app.use('/', viewRouter);
app.use('/api/v1/blog', blogRouter);
app.use('/api/v1/users', userRouter);
module.exports = app;