mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add inspect helper & warning (#1067)
This commit is contained in:
1 parent
5ebf48b694
commit
f32cee2200
2 files changed
+24
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
import { writeHeapSnapshot } from 'v8';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
import { lookup } from 'mime-types';
|
import { lookup } from 'mime-types';
|
||||||
import { Context } from '../context';
|
import { Context } from '../context';
|
||||||
@@ -139,10 +140,28 @@ export class SwitchAccountHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class HeapSnapshotHandler extends Handler {
|
||||||
|
@param('worker', Types.Int)
|
||||||
|
async post({ }, worker: number) {
|
||||||
|
this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
||||||
|
if (worker && process.env.NODE_APP_INSTANCE !== worker.toString()) {
|
||||||
|
this.response.body = { error: 'Not current worker' };
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.response.body = {
|
||||||
|
worker: process.env.NODE_APP_INSTANCE,
|
||||||
|
filename: writeHeapSnapshot(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function apply(ctx: Context) {
|
export async function apply(ctx: Context) {
|
||||||
ctx.Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
ctx.Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
||||||
ctx.Route('home_files', '/file', FilesHandler);
|
ctx.Route('home_files', '/file', FilesHandler);
|
||||||
ctx.Route('fs_download', '/file/:uid/:filename', FSDownloadHandler);
|
ctx.Route('fs_download', '/file/:uid/:filename', FSDownloadHandler);
|
||||||
ctx.Route('storage', '/storage', StorageHandler);
|
ctx.Route('storage', '/storage', StorageHandler);
|
||||||
ctx.Route('switch_account', '/account/:uid', SwitchAccountHandler, PRIV.PRIV_EDIT_SYSTEM);
|
ctx.Route('switch_account', '/account/:uid', SwitchAccountHandler, PRIV.PRIV_EDIT_SYSTEM);
|
||||||
|
if (process.argv.includes('--enable-heap-snapshot')) {
|
||||||
|
ctx.Route('heap_snapshot', '/heap-snapshot', HeapSnapshotHandler, PRIV.PRIV_EDIT_SYSTEM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import { DisposableList } from 'cordis';
|
import { DisposableList } from 'cordis';
|
||||||
|
import inspector from 'inspector';
|
||||||
import { randomstring } from '@hydrooj/utils';
|
import { randomstring } from '@hydrooj/utils';
|
||||||
import { Context, Service } from '../context';
|
import { Context, Service } from '../context';
|
||||||
import * as system from '../model/system';
|
import * as system from '../model/system';
|
||||||
@@ -49,6 +50,10 @@ export default class CheckService extends Service {
|
|||||||
const header = system.get('server.xff');
|
const header = system.get('server.xff');
|
||||||
if (header && !c.request.ip) warn('IP header seems incorrect.\nCheck dashboard>settings>server.');
|
if (header && !c.request.ip) warn('IP header seems incorrect.\nCheck dashboard>settings>server.');
|
||||||
});
|
});
|
||||||
|
this.addChecker('Inspector', async (c, log, warn) => {
|
||||||
|
const url = inspector.url();
|
||||||
|
if (url) warn(`Inspector is enabled at ${url}.`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addChecker(type: string, checkFunc: CheckItem) {
|
addChecker(type: string, checkFunc: CheckItem) {
|
||||||
|
|||||||
Reference in new issue
Block a user