From 4d42500e7622be66ffeb9a62f8529a0a5cb8dc05 Mon Sep 17 00:00:00 2001 From: Jason Macgowan Date: Wed, 6 Jun 2018 02:52:20 -0400 Subject: [PATCH] docs: better demonstrate middleware flow (#1195) --- docs/api/index.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 => {