forked from ikcamp/koa2-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (26 loc) · 786 Bytes
/
app.js
File metadata and controls
31 lines (26 loc) · 786 Bytes
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
const Koa = require('koa')
const app = new Koa()
const views = require("koa-views")
const nunjucks = require('nunjucks')
const path = require("path")
const staticFiles = require('koa-static')
const Router = require('koa-router')()
const BodyParser = require('koa-bodyparser')
const router = require("./route")
const nunjucksEnvironment = new nunjucks.Environment(
new nunjucks.FileSystemLoader(path.join(__dirname, './views'))
)
app.use(views(path.join(__dirname, '/views'), {
options: {
nunjucksEnv: nunjucksEnvironment
},
map: {
html: "nunjucks"
}
}))
app.use(staticFiles(path.resolve(__dirname, "./public")))
app.use(BodyParser())
app.use(Router.routes()).use(Router.allowedMethods())
router(Router)
app.listen(3000)
console.log(`app started at port 3000...`);