docs: better demonstrate middleware flow (#1195)
This commit is contained in:
parent
ee1a933096
commit
4d42500e76
1 changed files with 8 additions and 9 deletions
|
@ -78,6 +78,14 @@ app.listen(3000);
|
||||||
const Koa = require('koa');
|
const Koa = require('koa');
|
||||||
const app = new 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
|
// x-response-time
|
||||||
|
|
||||||
app.use(async (ctx, next) => {
|
app.use(async (ctx, next) => {
|
||||||
|
@ -87,15 +95,6 @@ app.use(async (ctx, next) => {
|
||||||
ctx.set('X-Response-Time', `${ms}ms`);
|
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
|
// response
|
||||||
|
|
||||||
app.use(async ctx => {
|
app.use(async ctx => {
|
||||||
|
|
Loading…
Reference in a new issue