code-center/src/admin/index.ts
2024-06-23 01:20:28 +08:00

47 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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);