-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.js
More file actions
36 lines (34 loc) · 802 Bytes
/
generator.js
File metadata and controls
36 lines (34 loc) · 802 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
32
33
34
35
36
/**
* Created by cag on 2016/12/8.
*/
var koa = require('koa');
var app = koa();
// X-Response-Time
app.use(function *(next) {
//this.body = 'hello koa!';
var start = new Date();
console.log(1111);
yield next;
console.log(11100000);
var ms = new Date() - start;
console.log('执行1,' + ms + 'ms');
this.set('X-Response-Time', ms + 'ms');
});
// logger
app.use(function *(next) {
console.log(222);
var start = new Date();
yield next;
console.log(2220000);
var ms = new Date() - start;
console.log('执行2,' + ms + 'ms');
});
// response
app.use(function *() {
console.log(333);
var start = new Date();
this.body = 'hello generator!';
var ms = new Date() - start;
console.log('执行3,' + ms + 'ms');
});
app.listen(3000);