core: fix 404 page display

This commit is contained in:
undefined committed 2025-05-07 21:37:52 +08:00
1 parent 83da1c8d66
commit cd56ffe55b
11 files changed
+48 -30

No files matched your search

+5 -5
View File
@@ -4,12 +4,12 @@
"license": "MIT",
"main": "base.mjs",
"dependencies": {
"@eslint-react/eslint-plugin": "^1.48.5",
"@eslint/compat": "^1.2.8",
"@eslint-react/eslint-plugin": "^1.49.0",
"@eslint/compat": "^1.2.9",
"@eslint/eslintrc": "^3.3.1",
"@stylistic/eslint-plugin": "^4.2.0",
"@typescript-eslint/eslint-plugin": "^8.31.0",
"@typescript-eslint/parser": "^8.31.0",
"@typescript-eslint/eslint-plugin": "^8.32.0",
"@typescript-eslint/parser": "^8.32.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-de-morgan": "^1.2.1",
"eslint-plugin-github": "^6.0.0",
@@ -18,7 +18,7 @@
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
"eslint-plugin-simple-import-sort": "^12.1.1",
"globals": "^16.0.0"
"globals": "^16.1.0"
},
"peerDependencies": {
"eslint": ">= 9"
+1 -1
View File
@@ -20,7 +20,7 @@
"sanitize-filename": "^1.6.3",
"saslprep": "^1.0.3",
"shorty.js": "^1.0.1",
"ws": "^8.18.1"
"ws": "^8.18.2"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
+17 -1
View File
@@ -343,6 +343,7 @@ export class WebService<C extends CordisContext = CordisContext> extends Service
private handlerLayers = [];
private wsLayers = [];
private captureAllRoutes = Object.create(null);
private customDefaultContext: C;
renderers: Record<string, Renderer> = Object.create(null);
server = koa;
@@ -449,7 +450,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
...this.handlerLayers,
{
name: '404',
func: (t) => this.handleHttp(t, NotFoundHandler, () => true, this.ctx),
func: (t) => this.handleHttp(t, NotFoundHandler, () => true, this.customDefaultContext || this.ctx),
},
]));
this.addLayer('base', base(logger, this.config.xff, this.config.xhost));
@@ -736,6 +737,21 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
});
}
public setDefaultContext(ctx: C) {
try {
if (!ctx.server) throw new Error();
} catch (e) {
throw new Error('Must provide a valid context with server.');
}
this.ctx.effect(async () => {
if (this.customDefaultContext) logger.warn('Default context already set.');
this.customDefaultContext = ctx;
return () => {
this.customDefaultContext = null;
};
});
}
public withHandlerClass<T extends string>(
name: T, callback: (HandlerClass: T extends `${string}ConnectionHandler` ? typeof ConnectionHandler<C> : typeof Handler<C>) => any,
) {