-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
77 lines (49 loc) · 1.4 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
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const path = require('path');
const spdy = require('spdy');
const fs = require('fs');
const koa = require('koa');
const config = require('./config/config');
const app = koa();
app.keys = ['rebase'];
const compress = require('koa-compress');
app.use(compress());
const onerror = require('koa-onerror');
onerror(app);
const sass = require('koa-sass');
app.use(sass({
src: path.join(config.staticDir, 'sass'),
prefix: '/sass/',
force: true,
response: true
}));
const staticCache = require('koa-static-cache');
app.use(staticCache(config.staticDir, {
dynamic: true,
}));
const session = require('koa-generic-session');
app.use(session(app));
const bodyParser = require('koa-bodyparser');
app.use(bodyParser());
const ejs = require('koa-ejs');
ejs(app, {
root: config.viewDir,
layout: 'layout',
viewExt: 'html',
cache: false,
debug: true
});
const csrf = require('koa-csrf');
csrf(app);
app.use(csrf.middleware);
const router = require('koa-router')();
const indexRouter = require('./router/index');
router.use('/', indexRouter.routes());
app.use(router.routes());
const options = {
key: fs.readFileSync(__dirname + '/keys/server-key.pem'),
cert: fs.readFileSync(__dirname + '/keys/server-cert.pem'),
ca: fs.readFileSync(__dirname + '/keys/ca-cert.pem'),
};
const server = spdy.createServer(options, app.callback());
server.listen(config.port);