-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.js
43 lines (37 loc) · 963 Bytes
/
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
/**!
* Demos - app.js
*
* 项目入口文件
*
* Authors:
* Berwin <liubowen.niubi@gmail.com>
*/
var app = require('koa')();
var path = require('path');
var logger = require('koa-logger');
var serve = require('koa-static');
var bodyParser = require('koa-bodyparser');
var render = require('koa-ejs');
var route = require('./routes/index.js');
var config = require('./config/index.js');
// 注册中间件
app.use(logger());
app.use(serve(path.join(__dirname, 'public')));
app.use(bodyParser());
render(app, {
root: path.join(__dirname, 'views'),
layout: false,
viewExt: 'ejs',
cache: false,
debug: true
});
app.use(route.routes());
if (!module.parent) {
var server = app.listen(config.port, function () {
console.info(`Demos listening on port ${config.port}`);
console.info(`God bless love....`);
console.info(`You can debug your app with http://127.0.0.1:${config.port}`);
console.info('');
});
}
module.exports = app;