forked from Dragon-Rider/node-server
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (24 loc) · 718 Bytes
/
app.js
File metadata and controls
29 lines (24 loc) · 718 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
'use strict';
const Koa = require('koa');
const staticServe = require('koa-static');
const mount = require('koa-mount');
const render = require('koa-ejs');
const path = require('path');
const logger = require('koa-logger');
const onerror = require('koa-onerror');
const staticDirectory = staticServe(__dirname + '/src/public');
const router = require('./src/routes');
const config = require('./config');
const app = new Koa();
// 设置模板引擎
render(app, {
root: path.join(__dirname, '/src/views'),
viewExt: 'ejs',
layout: false
});
// 错误监听
onerror(app);
app .use(logger())
.use(mount('/static', staticDirectory))
.use(router.routes());
app.listen(config.listenPort, '0.0.0.0');