Skip to content

Commit

Permalink
fix: Skip processing undefined namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nczitzk committed Jan 2, 2025
1 parent d4e2c94 commit 22c0027
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ if (Object.keys(modules).length) {
export { namespaces };

const app = new Hono();
const sortRoutes = (routes: Record<string, Route & { location: string }>) =>
const sortRoutes = (
routes: Record<
string,
Route & {
location: string;
}
>
) =>
Object.entries(routes).sort(([pathA], [pathB]) => {
const segmentsA = pathA.split('/');
const segmentsB = pathB.split('/');
Expand All @@ -108,7 +115,12 @@ const sortRoutes = (routes: Record<string, Route & { location: string }>) =>
for (const namespace in namespaces) {
const subApp = app.basePath(`/${namespace}`);

const sortedRoutes = sortRoutes(namespaces[namespace].routes);
const namespaceData = namespaces[namespace];
if (!namespaceData || !namespaceData.routes) {
continue;
}

const sortedRoutes = sortRoutes(namespaceData.routes);

for (const [path, routeData] of sortedRoutes) {
const wrappedHandler: Handler = async (ctx) => {
Expand Down

0 comments on commit 22c0027

Please sign in to comment.