diff --git a/docs/api/index.md b/docs/api/index.md index d94b81e..7969872 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -78,6 +78,14 @@ app.listen(3000); const Koa = require('koa'); const app = new Koa(); +// logger + +app.use(async (ctx, next) => { + await next(); + const rt = ctx.response.get('X-Response-Time'); + console.log(`${ctx.method} ${ctx.url} - ${rt}`); +}); + // x-response-time app.use(async (ctx, next) => { @@ -87,15 +95,6 @@ app.use(async (ctx, next) => { ctx.set('X-Response-Time', `${ms}ms`); }); -// logger - -app.use(async (ctx, next) => { - const start = Date.now(); - await next(); - const ms = Date.now() - start; - console.log(`${ctx.method} ${ctx.url} - ${ms}`); -}); - // response app.use(async ctx => {