diff --git a/index.js b/index.js
index 3d6f8ab604..7171762c63 100644
--- a/index.js
+++ b/index.js
@@ -11,6 +11,7 @@ const redisCache = require('./middleware/redis-cache.js');
const filter = require('./middleware/filter.js');
const template = require('./middleware/template.js');
const favicon = require('koa-favicon');
+const debug = require('./middleware/debug.js');
const router = require('./router');
@@ -28,19 +29,26 @@ app.use(favicon(__dirname + '/favicon.png'));
// global error handing
app.use(onerror);
-// set header
+// 1 set header
app.use(header);
-// fix incorrect `utf-8` characters
+// 6 debug
+app.context.debug = {
+ hitCache: 0,
+ request: 0,
+};
+app.use(debug);
+
+// 5 fix incorrect `utf-8` characters
app.use(utf8);
-// generate body
+// 4 generate body
app.use(template);
-// filter content
+// 3 filter content
app.use(filter);
-// cache
+// 2 cache
if (config.cacheType === 'memory') {
app.use(
memoryCache({
diff --git a/middleware/debug.js b/middleware/debug.js
new file mode 100644
index 0000000000..2b0e0b5114
--- /dev/null
+++ b/middleware/debug.js
@@ -0,0 +1,10 @@
+module.exports = async (ctx, next) => {
+ await next();
+
+ if (ctx.request.path !== '/') {
+ ctx.debug.request++;
+ if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
+ ctx.debug.hitCache++;
+ }
+ }
+};
diff --git a/package.json b/package.json
index 555c5b858e..e70fded190 100644
--- a/package.json
+++ b/package.json
@@ -51,6 +51,7 @@
"co-redis": "2.1.1",
"crypto": "1.0.1",
"form-data": "^2.3.2",
+ "git-rev-sync": "1.12.0",
"googleapis": "30.0.0",
"iconv-lite": "0.4.23",
"json-bigint": "0.2.3",
diff --git a/router.js b/router.js
index 12a12e49d2..55a62f6f49 100644
--- a/router.js
+++ b/router.js
@@ -5,11 +5,46 @@ const path = require('path');
const config = require('./config');
const logger = require('./utils/logger');
+let gitHash;
+try {
+ gitHash = require('git-rev-sync').short();
+} catch (e) {
+ gitHash = process.env.HEROKU_SLUG_COMMIT.slice(0, 7) || 'unknown';
+}
+const startTime = +new Date();
router.get('/', async (ctx) => {
ctx.set({
'Content-Type': 'text/html; charset=UTF-8',
});
- ctx.body = art(path.resolve(__dirname, './views/welcome.art'), {});
+ const time = (+new Date() - startTime) / 1000;
+ ctx.body = art(path.resolve(__dirname, './views/welcome.art'), {
+ debug: [
+ {
+ name: 'git hash',
+ value: gitHash,
+ },
+ {
+ name: '请求数',
+ value: ctx.debug.request,
+ },
+ {
+ name: '请求频率',
+ value: (ctx.debug.request / time * 60).toFixed(3) + ' 次/分钟',
+ },
+ {
+ name: '缓存命中率',
+ value: ctx.debug.request ? (ctx.debug.hitCache / ctx.debug.request).toFixed(3) : 0,
+ },
+ {
+ name: '内存占用',
+ value: process.memoryUsage().rss + ' Byte',
+ },
+ {
+ name: '运行时间',
+ value: time + ' 秒',
+ },
+ ],
+ });
});
// bilibili
diff --git a/views/welcome.art b/views/welcome.art
index 87f3e4650a..39ba0aa273 100644
--- a/views/welcome.art
+++ b/views/welcome.art
@@ -1,43 +1,82 @@
+
-Welcome to RSSHub!
-
+ .content {
+ position: absolute;
+ top: 40%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ min-width: 400px;
+ text-align: center;
+ }
+
+ details {
+ text-align: left;
+ }
+
+ summary {
+ margin-bottom: 20px;
+ outline: none;
+ cursor: pointer;
+ }
+
+ .debug-key {
+ width: 100px;
+ text-align: right;
+ display: inline-block;
+ margin-right: 10px;
+ }
+
+ .debug-item {
+ margin: 10px 0;
+ font-size: 14px;
+ }
+
+
+
-
-

+
+
+
+
-
Welcome to RSSHub!
+
Welcome to
+ RSSHub!
-
If you see this page, the RSSHub{{ if hash }} ({{ hash }}){{ /if }} is successfully installed and working.
+
If you see this page, the RSSHub{{ if hash }} ({{ hash }}){{ /if }} is successfully installed and working.
-
For online documentation and support please refer to
- rsshub.js.org.
+
For online documentation and support please refer to
+ rsshub.js.org.
-
-- Made with
- ♥ by
- DIYgod
-
-
+
-- Made with
+ ♥ by
+ DIYgod
+
+
+
+ debug
+ {{ each debug }}
+
+ {{ $value.name }}:
+ {{ $value.value }}
+
+ {{ /each }}
+
+
-
\ No newline at end of file
+
+