mirror of
https://github.com/laochan-eacnet/backend.git
synced 2026-09-27 09:23:10 +03:00
add static serving for control-panel and fix bigint json serialization for api
This commit is contained in:
@@ -35,3 +35,5 @@ output.json
|
||||
dump.xml
|
||||
pdata.json
|
||||
dump.bin
|
||||
|
||||
static
|
||||
|
||||
Generated
+401
-288
File diff suppressed because it is too large
Load Diff
@@ -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
@@ -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.';
|
||||
|
||||
Reference in New Issue
Block a user