47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
// 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.add(new Route(path, key));
|
||
ctx.body = 'success';
|
||
return ctx;
|
||
}
|
||
router.add(updateRouter);
|