feat: add export and import

This commit is contained in:
2024-10-25 19:41:01 +08:00
parent 6f0faba703
commit 158b12d811
10 changed files with 115 additions and 17 deletions

View File

@@ -439,7 +439,7 @@ export class QueryRouter {
return await this.runRoute(path, key, ctx);
}
// clear body
ctx.body = JSON.parse(JSON.stringify(ctx.body||''));
ctx.body = JSON.parse(JSON.stringify(ctx.body || ''));
if (!ctx.code) ctx.code = 200;
return ctx;
} else {
@@ -492,6 +492,19 @@ export class QueryRouter {
return { code, data: body, message };
};
}
exportRoutes() {
return this.routes.map((r) => {
return r;
});
}
importRoutes(routes: Route[]) {
for (let route of routes) {
this.add(route);
}
}
importRouter(router: QueryRouter) {
this.importRoutes(router.routes);
}
}
type QueryRouterServerOpts = {