feat: add admin router manager

This commit is contained in:
xion
2024-06-25 00:52:43 +08:00
parent f8777bd4ea
commit 3454e39ea4
18 changed files with 831 additions and 368 deletions

25
src/demo/index.ts Normal file
View File

@@ -0,0 +1,25 @@
import { router } from '../modules/router.ts';
import { Route } from '@abearxiong/router';
const getList = new Route('test', 'getList');
getList.run = async (ctx) => {
ctx.body = 'test';
return ctx;
};
router.add(getList);
const codeRun = `async function run(ctx) {
ctx.body = 'test js';
return ctx;
}`;
const fn: any = new Function(
'ctx',
`
${codeRun}
return run(ctx);
`,
);
const codeRunRoute = new Route('test', 'run');
codeRunRoute.run = fn;
router.add(codeRunRoute);