mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 10:15:23 +08:00
app: debug info
This commit is contained in:
18
index.js
18
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({
|
||||
|
||||
10
middleware/debug.js
Normal file
10
middleware/debug.js
Normal file
@@ -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++;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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",
|
||||
|
||||
37
router.js
37
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
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Welcome to RSSHub!</title>
|
||||
<style>
|
||||
<title>Welcome to RSSHub!</title>
|
||||
<style>
|
||||
body {
|
||||
width: 35em;
|
||||
margin: 0 auto;
|
||||
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;
|
||||
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
font-size: 16px;
|
||||
@@ -21,13 +22,40 @@
|
||||
min-width: 400px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<p><img src="https://i.imgur.com/NZpRScX.png" alt="RSSHub" width="100"></p>
|
||||
|
||||
<h1>Welcome to <span style="color: #F5712C;">RSSHub</span>!</h1>
|
||||
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;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="content">
|
||||
<p>
|
||||
<img src="https://i.imgur.com/NZpRScX.png" alt="RSSHub" width="100">
|
||||
</p>
|
||||
|
||||
<h1>Welcome to
|
||||
<span style="color: #F5712C;">RSSHub</span>!</h1>
|
||||
|
||||
<p>If you see this page, the RSSHub{{ if hash }} ({{ hash }}){{ /if }} is successfully installed and working.</p>
|
||||
|
||||
@@ -38,6 +66,17 @@
|
||||
<i style="color:#d43f57">♥</i> by
|
||||
<a href="https://diygod.me" target="_blank">DIYgod</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<details>
|
||||
<summary>debug</summary>
|
||||
{{ each debug }}
|
||||
<div class="debug-item">
|
||||
<span class="debug-key">{{ $value.name }}: </span>
|
||||
<span class="debug-value">{{ $value.value }}</span>
|
||||
</div>
|
||||
{{ /each }}
|
||||
</details>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
34
yarn.lock
34
yarn.lock
@@ -1880,7 +1880,7 @@ escape-html@^1.0.3, escape-html@~1.0.1:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
|
||||
|
||||
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
|
||||
escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
|
||||
@@ -2412,6 +2412,14 @@ getpass@^0.1.1:
|
||||
dependencies:
|
||||
assert-plus "^1.0.0"
|
||||
|
||||
git-rev-sync@1.12.0:
|
||||
version "1.12.0"
|
||||
resolved "https://registry.npmjs.org/git-rev-sync/-/git-rev-sync-1.12.0.tgz#4468406c7e6c3ba4cf4587999e1adb28d9d1af55"
|
||||
dependencies:
|
||||
escape-string-regexp "1.0.5"
|
||||
graceful-fs "4.1.11"
|
||||
shelljs "0.7.7"
|
||||
|
||||
glob-base@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.npmjs.org/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4"
|
||||
@@ -2447,7 +2455,7 @@ glob@7.0.x:
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
|
||||
glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
|
||||
version "7.1.2"
|
||||
resolved "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
|
||||
dependencies:
|
||||
@@ -2560,7 +2568,7 @@ got@^6.7.1:
|
||||
unzip-response "^2.0.1"
|
||||
url-parse-lax "^1.0.0"
|
||||
|
||||
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
|
||||
graceful-fs@4.1.11, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
|
||||
version "4.1.11"
|
||||
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
|
||||
|
||||
@@ -2886,6 +2894,10 @@ inquirer@^3.0.6:
|
||||
strip-ansi "^4.0.0"
|
||||
through "^2.3.6"
|
||||
|
||||
interpret@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.npmjs.org/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
|
||||
|
||||
is-absolute-url@^2.0.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.npmjs.org/is-absolute-url/-/is-absolute-url-2.1.0.tgz#50530dfb84fcc9aa7dbe7852e83a37b93b9f2aa6"
|
||||
@@ -5286,6 +5298,12 @@ readdirp@^2.0.0:
|
||||
readable-stream "^2.0.2"
|
||||
set-immediate-shim "^1.0.1"
|
||||
|
||||
rechoir@^0.6.2:
|
||||
version "0.6.2"
|
||||
resolved "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
|
||||
dependencies:
|
||||
resolve "^1.1.6"
|
||||
|
||||
redent@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npmjs.org/redent/-/redent-2.0.0.tgz#c1b2007b42d57eb1389079b3c8333639d5e1ccaa"
|
||||
@@ -5509,7 +5527,7 @@ resolve@1.1.7:
|
||||
version "1.1.7"
|
||||
resolved "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
|
||||
|
||||
resolve@^1.2.0, resolve@^1.6.0:
|
||||
resolve@^1.1.6, resolve@^1.2.0, resolve@^1.6.0:
|
||||
version "1.7.1"
|
||||
resolved "https://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3"
|
||||
dependencies:
|
||||
@@ -5687,6 +5705,14 @@ shebang-regex@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
|
||||
|
||||
shelljs@0.7.7:
|
||||
version "0.7.7"
|
||||
resolved "https://registry.npmjs.org/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1"
|
||||
dependencies:
|
||||
glob "^7.0.0"
|
||||
interpret "^1.0.0"
|
||||
rechoir "^0.6.2"
|
||||
|
||||
signal-exit@^3.0.0, signal-exit@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
||||
|
||||
Reference in New Issue
Block a user