// 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); // remove router by id export const removeRouterById = new Route('admin', 'removeRouterById'); removeRouterById.run = async (ctx) => { const { id } = ctx.query; router.removeById(id); ctx.body = 'success'; return ctx; } router.add(removeRouterById); // 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);