위치 이동

This commit is contained in:
2023-08-06 11:02:03 +00:00
parent 3432009213
commit 19a19d8a2f
9 changed files with 6 additions and 16 deletions
+21
View File
@@ -0,0 +1,21 @@
import { Router } from 'express';
import type { APIExecuter, APINamespace } from './defs.js';
export function buildAPISystem<N extends APINamespace, Q extends APIExecuter<any, any, any>>(api: N | Q): Router {
const router = Router();
for (const [key, value] of Object.entries(api)) {
if (typeof value === 'function') {
const executer = new value() as Q;
if (!executer.reqType) {
throw new Error('APIExecuter.reqType is not defined');
}
router[executer.reqType](key, async (req, res) => {
await executer.run(req, res);
});
continue;
} else {
router.use(key, buildAPISystem(value));
}
}
return router;
}