-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (35 loc) · 880 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
44
var koa = require('koa');
var router = require('koa-router')();
var serve = require('koa-static');
var app = koa();
// x-response-time
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
this.set('X-Response-Time', ms + 'ms');
});
// logger
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
console.log('%s %s - %s', this.method, this.url, ms);
});
// static
app.use(serve(__dirname + '/public'));
// response
require('./config/koa')(app);
// Routes
require('./config/routers')(app);
//router.get('/', function *(next) {
// this.type = 'ejs';
// this.body = yield this.render("index");
//});
//
//app.use(router.routes());
//app.use(router.allowedMethods());
app.on('error', function(err, ctx){
console.error('server error', err, ctx);
});
app.listen(3000);