강력한 API 타입 체크
This commit is contained in:
+5
-12
@@ -6,20 +6,13 @@ export function buildAPISystem<N extends APINamespace, Q extends APIExecuter<any
|
||||
for (const [key, value] of Object.entries(api)) {
|
||||
if (typeof value === 'function') {
|
||||
const executer = new value() as Q;
|
||||
if(!executer.reqType){
|
||||
if (!executer.reqType) {
|
||||
throw new Error('APIExecuter.reqType is not defined');
|
||||
}
|
||||
if(!Array.isArray(executer.reqType)){
|
||||
router[executer.reqType](key, async (req, res) => {
|
||||
await executer.run(req, res);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
for(const type of new Set(executer.reqType)){
|
||||
router[type](key, async (req, res) => {
|
||||
await executer.run(req, res);
|
||||
});
|
||||
}
|
||||
router[executer.reqType](key, async (req, res) => {
|
||||
await executer.run(req, res);
|
||||
});
|
||||
continue;
|
||||
} else {
|
||||
router.use(key, buildAPISystem(value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user