feat: init base module
This commit is contained in:
45
src/admin/index.ts
Normal file
45
src/admin/index.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// admin 需要最后运行,并在route中进行过滤。
|
||||
import { Route } from '@abearxiong/router';
|
||||
import { router } from '../modules/router.ts';
|
||||
|
||||
|
||||
export const getRouterList = new Route('admin', 'getRouterList');
|
||||
|
||||
getRouterList.run = async (ctx) => {
|
||||
// ctx.body = router.getList().filter((r) => r.path.startsWith('admin'));
|
||||
ctx.body = router.getList().filter((r) => r.path.startsWith('admin'));
|
||||
return ctx;
|
||||
};
|
||||
|
||||
router.add(getRouterList);
|
||||
|
||||
// remove router
|
||||
|
||||
export const removeRouter = new Route('admin', 'removeRouter');
|
||||
removeRouter.run = async (ctx) => {
|
||||
const { path, key } = ctx.query;
|
||||
router.remove({path, key});
|
||||
ctx.body = 'success';
|
||||
return ctx;
|
||||
}
|
||||
router.add(removeRouter);
|
||||
|
||||
// add router
|
||||
export const addRouter = new Route('admin', 'addRouter');
|
||||
addRouter.run = async (ctx) => {
|
||||
const { path, key } = ctx.query;
|
||||
router.add(new Route(path, key));
|
||||
ctx.body = 'success';
|
||||
return ctx;
|
||||
}
|
||||
router.add(addRouter);
|
||||
|
||||
// update router
|
||||
export const updateRouter = new Route('admin', 'updateRouter');
|
||||
updateRouter.run = async (ctx) => {
|
||||
const { path, key } = ctx.query;
|
||||
// router.update(path, key);
|
||||
ctx.body = 'success';
|
||||
return ctx;
|
||||
}
|
||||
router.add(updateRouter);
|
||||
Reference in New Issue
Block a user