feat: add admin router manager
This commit is contained in:
25
src/demo/index.ts
Normal file
25
src/demo/index.ts
Normal 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);
|
||||
Reference in New Issue
Block a user