Files

25 lines
641 B
JavaScript
Raw Permalink Normal View History

2018-05-17 12:22:52 +08:00
module.exports = async (ctx, next) => {
2019-06-19 18:39:40 +08:00
if (!ctx.debug.paths[ctx.request.path]) {
ctx.debug.paths[ctx.request.path] = 0;
2018-05-17 15:01:45 +08:00
}
2019-06-19 18:39:40 +08:00
ctx.debug.paths[ctx.request.path]++;
2018-05-17 12:22:52 +08:00
2019-01-29 18:22:59 +08:00
ctx.debug.request++;
2018-05-17 15:01:45 +08:00
await next();
2019-06-19 18:39:40 +08:00
if (!ctx.debug.routes[ctx._matchedRoute]) {
ctx._matchedRoute && (ctx.debug.routes[ctx._matchedRoute] = 0);
2019-06-19 18:39:40 +08:00
}
ctx._matchedRoute && ctx.debug.routes[ctx._matchedRoute]++;
2019-06-19 18:39:40 +08:00
2019-01-29 18:22:59 +08:00
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
ctx.debug.hitCache++;
2018-05-17 12:22:52 +08:00
}
2019-09-04 21:56:16 +08:00
ctx.state.debuged = true;
2020-09-29 18:53:24 +08:00
if (ctx.status === 304) {
ctx.debug.etag++;
}
2018-05-17 12:22:52 +08:00
};