mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
27 lines
556 B
TypeScript
27 lines
556 B
TypeScript
|
|
|
|
import * as Koa from 'koa';
|
|
var app = new Koa();
|
|
|
|
// logger
|
|
|
|
app.use(function *(next: Function) {
|
|
// at present, we can not typing 'this' in function
|
|
// but there is a proposal: https://github.com/Microsoft/TypeScript/issues/3694
|
|
var ctx: Koa.Context = this;
|
|
|
|
var start = new Date;
|
|
yield next;
|
|
var ms = <any>new Date - <any>start;
|
|
console.log('%s %s - %s', ctx.method, ctx.url, ms);
|
|
});
|
|
|
|
// response
|
|
|
|
app.use(function *(): Iterable<void> {
|
|
var ctx: Koa.Context = this;
|
|
ctx.body = 'Hello World';
|
|
});
|
|
|
|
app.listen(3000);
|