diff --git a/lib/middleware/debug.js b/lib/middleware/debug.js
index a1357f54c5..5167bc843a 100644
--- a/lib/middleware/debug.js
+++ b/lib/middleware/debug.js
@@ -21,4 +21,6 @@ module.exports = async (ctx, next) => {
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
ctx.debug.hitCache++;
}
+
+ ctx.state.debuged = true;
};
diff --git a/lib/middleware/onerror.js b/lib/middleware/onerror.js
index 1bb5ae8476..5a67fb3ea9 100644
--- a/lib/middleware/onerror.js
+++ b/lib/middleware/onerror.js
@@ -42,6 +42,17 @@ module.exports = async (ctx, next) => {
}
ctx.debug.errorRoutes[ctx._matchedRoute]++;
+ if (!ctx.state.debuged) {
+ if (!ctx.debug.routes[ctx._matchedRoute]) {
+ ctx.debug.routes[ctx._matchedRoute] = 0;
+ }
+ ctx.debug.routes[ctx._matchedRoute]++;
+
+ if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
+ ctx.debug.hitCache++;
+ }
+ }
+
if (config.sentry) {
Sentry.withScope((scope) => {
scope.setTag('route', ctx._matchedRoute);
diff --git a/lib/routes/index.js b/lib/routes/index.js
index 847d2d06fb..5920f93086 100644
--- a/lib/routes/index.js
+++ b/lib/routes/index.js
@@ -19,14 +19,14 @@ module.exports = async (ctx) => {
const hotRoutes = routes.slice(0, 30);
let hotRoutesValue = '';
hotRoutes.forEach((item) => {
- hotRoutesValue += `${ctx.debug.routes[item]} ${item}
`;
+ hotRoutesValue += `${ctx.debug.routes[item]} ${item}
`;
});
const paths = Object.keys(ctx.debug.paths).sort((a, b) => ctx.debug.paths[b] - ctx.debug.paths[a]);
const hotPaths = paths.slice(0, 30);
let hotPathsValue = '';
hotPaths.forEach((item) => {
- hotPathsValue += `${ctx.debug.paths[item]} ${item}
`;
+ hotPathsValue += `${ctx.debug.paths[item]} ${item}
`;
});
let hotErrorRoutesValue = '';
@@ -34,7 +34,7 @@ module.exports = async (ctx) => {
const errorRoutes = Object.keys(ctx.debug.errorRoutes).sort((a, b) => ctx.debug.errorRoutes[b] - ctx.debug.errorRoutes[a]);
const hotErrorRoutes = errorRoutes.slice(0, 30);
hotErrorRoutes.forEach((item) => {
- hotErrorRoutesValue += `${ctx.debug.errorRoutes[item]} ${item}
`;
+ hotErrorRoutesValue += `${ctx.debug.errorRoutes[item]} ${item}
`;
});
}
@@ -43,7 +43,7 @@ module.exports = async (ctx) => {
const errorPaths = Object.keys(ctx.debug.errorPaths).sort((a, b) => ctx.debug.errorPaths[b] - ctx.debug.errorPaths[a]);
const hotErrorPaths = errorPaths.slice(0, 30);
hotErrorPaths.forEach((item) => {
- hotErrorPathsValue += `${ctx.debug.errorPaths[item]} ${item}
`;
+ hotErrorPathsValue += `${ctx.debug.errorPaths[item]} ${item}
`;
});
}
@@ -51,7 +51,7 @@ module.exports = async (ctx) => {
const hotIPs = ips.slice(0, 50);
let hotIPsValue = '';
hotIPs.forEach((item) => {
- hotIPsValue += `${ctx.debug.ips[item]} ${item}
`;
+ hotIPsValue += `${ctx.debug.ips[item]} ${item}
`;
});
let showDebug;
diff --git a/lib/views/welcome.art b/lib/views/welcome.art
index 3182aec8c9..800409772b 100644
--- a/lib/views/welcome.art
+++ b/lib/views/welcome.art
@@ -65,6 +65,7 @@
.debug-value {
display: inline-block;
vertical-align: top;
+ white-space: pre;
}
diff --git a/test/middleware/debug.js b/test/middleware/debug.js
index d9a8358bfa..43995cca21 100644
--- a/test/middleware/debug.js
+++ b/test/middleware/debug.js
@@ -48,19 +48,19 @@ describe('debug', () => {
expect(value).toBe('8');
break;
case 'hot routes:':
- expect(value).toBe(`7 /test/:id
`);
+ expect(value).toBe(`7 /test/:id
`);
break;
case 'hot paths:':
- expect(value).toBe(`3 /test/1
2 /test/2
2 /test/empty
1 /
`);
+ expect(value).toBe(`3 /test/1
2 /test/2
2 /test/empty
1 /
`);
break;
case 'hot IP:':
- expect(value).toBe(`5 233.233.233.233
3 233.233.233.234
`);
+ expect(value).toBe(`5 233.233.233.233
3 233.233.233.234
`);
break;
case 'hot error routes:':
- expect(value).toBe(`2 /test/:id
`);
+ expect(value).toBe(`2 /test/:id
`);
break;
case 'hot error paths:':
- expect(value).toBe(`2 /test/empty
`);
+ expect(value).toBe(`2 /test/empty
`);
break;
}
});