feat: add export and import
This commit is contained in:
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