add static serving for control-panel and fix bigint json serialization for api

This commit is contained in:
GEEKiDoS
2026-04-03 00:25:56 +08:00
parent f357c2b32e
commit 32f3c4c4ed
4 changed files with 426 additions and 289 deletions
+2
View File
@@ -35,3 +35,5 @@ output.json
dump.xml
pdata.json
dump.bin
static
+401 -288
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -58,6 +58,7 @@
"highwayhash": "^3.1.1",
"koa": "^2.15.0",
"koa-bodyparser": "^4.4.1",
"koa-static": "^5.0.0",
"lodash": "^4.17.21",
"mongodb": "^6.4.0",
"node-cache": "^5.1.2",
+22 -1
View File
@@ -3,6 +3,7 @@ import 'reflect-metadata';
import cors from '@koa/cors';
import Koa, { DefaultState } from 'koa';
import bodyParser from 'koa-bodyparser';
import serve from "koa-static";
import { InjectionToken, Provider, container } from 'tsyringe';
import { ILaochanContext } from './types.js';
@@ -151,7 +152,27 @@ async function main(): Promise<void> {
ctx.logger.info('[server]: status = %d', ctx.status);
})
.use(apiRoutes)
.use(async (ctx, next) => {
let matchApi = true;
await apiRoutes(ctx as any, async () => {
matchApi = false;
});
if (matchApi) {
ctx.body = JSON.stringify(ctx.body, (_, v) => {
if (typeof v === 'bigint') {
return v.toString();
}
return v;
});
ctx.set('Content-Type', 'application/json');
return;
}
await next();
})
.use(serve('static'))
.use(async (ctx, next) => {
if (!ctx.body) {
ctx.body = 'Laochan-Eacnet is running.';