feat: add export and import
This commit is contained in:
@@ -81,4 +81,13 @@ export class App<T = {}> {
|
||||
const router = this.router;
|
||||
return await router.parse(message, ctx);
|
||||
}
|
||||
exportRoutes() {
|
||||
return this.router.exportRoutes();
|
||||
}
|
||||
importRoutes(routes: any[]) {
|
||||
this.router.importRoutes(routes);
|
||||
}
|
||||
importApp(app: App) {
|
||||
this.importRoutes(app.exportRoutes());
|
||||
}
|
||||
}
|
||||
|
||||
15
src/route.ts
15
src/route.ts
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user