-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
56 lines (50 loc) · 1.34 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
const Koa = require('koa');
const app = new Koa();
const config = require('config');
const path = require('path');
const router = require('./router');
require('./db');
app.keys = config.keys;
app.proxy = true;
if (process.env.NODE_ENV === 'production') {
app.silent = true;
app.use(require('koa-pino-logger')({
base: null
}));
} else {
app.use(require('koa-logger')());
}
app.use(require('koa-helmet')({
hsts: false,
frameguard: {
action: 'deny'
},
referrerPolicy: {
policy: 'strict-origin'
},
contentSecurityPolicy: {
directives: {
'default-src': ["'none'"],
'base-uri': ["'none'"],
'connect-src': ["'self'"],
'font-src': ["'self'", 'https://fonts.gstatic.com'],
'form-action': ["'self'"],
'frame-ancestors': ["'none'"],
'img-src': ["'self'", 'https:', 'data:'],
'object-src': ["'none'"],
'script-src': ["'self'", 'https://cdnjs.cloudflare.com', 'https://code.jquery.com'],
'style-src': ["'self'", 'https://fonts.googleapis.com', 'https://cdnjs.cloudflare.com'],
'block-all-mixed-content': true
}
}
}));
app.use(require('koa-compress')());
app.use(require('koa-static-cache')(path.join(__dirname, 'public'), {
maxAge: config.cacheAge
}));
app.use(require('koa-views')(path.join(__dirname, 'views'), {
extension: 'pug'
}));
app.use(router.routes());
app.use(router.allowedMethods());
module.exports = app;