-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (46 loc) · 1.21 KB
/
index.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
const Koa = require('koa')
const path = require('path')
const serve = require('koa-static')
const views = require('koa-views')
const session = require('koa-session')
const bodyParser = require('koa-bodyparser')
const mongoose = require('mongoose')
const marked = require('marked')
const error = require('./middlewares/error_handler')
const flash = require('./middlewares/flash')
const router = require('./routes')
const CONFIG = require('./config/config')
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
})
const app = module.exports = new Koa()
app.use(error())
mongoose.connect(CONFIG.mongodb)
app.keys = ['jszen']
app.use(bodyParser())
app.use(session({
key: CONFIG.session.key,
maxAge: CONFIG.session.maxAge
}, app))
app.use(flash())
app.use(serve(
path.join(__dirname, 'public')
))
app.use(views(path.join(__dirname, 'views'), {
map: { html: 'nunjucks' }
}))
app.use(async (ctx, next) => {
ctx.state.ctx = ctx
ctx.state.marked = marked
await next()
})
router(app)
if (!module.parent) app.listen(CONFIG.port)
console.log(`server is running at http://localhost:${CONFIG.port}`)