Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update H3Adapter.ts use that for unjs/nitro #866

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/h3/src/H3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class H3Adapter implements IServerAdapter {
private bullBoardQueues: BullBoardQueues | undefined;
private viewPath: string | undefined;
private uiConfig: UIConfig = {};
private routes: Array<any> = [];

public setBasePath(path: string): H3Adapter {
this.basePath = path;
Expand Down Expand Up @@ -59,13 +60,23 @@ export class H3Adapter implements IServerAdapter {
const methods = Array.isArray(methodOrMethods) ? methodOrMethods : [methodOrMethods];

methods.forEach((method) => {
this.registerRoute(route, method, handler);
// this.registerRoute(route, method, handler);
this.routes.push({ route, method, handler });
});
});

return this;
}

generateApiRoutes() {
this.routes.forEach(({ route, handler, method: methodOrMethods }) => {
const methods = Array.isArray(methodOrMethods) ? methodOrMethods : [methodOrMethods];
methods.forEach((method) => {
this.registerRoute(route, method, handler);
});
});
}

public setEntryRoute(routeDef: AppViewRoute): H3Adapter {
this.entryRoute = routeDef;

Expand Down Expand Up @@ -96,6 +107,7 @@ export class H3Adapter implements IServerAdapter {
throw new Error(`Please call 'setUIConfig' before using 'registerHandlers'`);
}

this.generateApiRoutes();
const getStaticPath = (relativePath: string) => {
if (!this.statics) return '';

Expand Down