위치 이동
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user