fix: middleware default export ignored (#2680)

Fixes https://github.com/denoland/fresh/issues/2657
This commit is contained in:
Marvin Hagemeister
2024-10-04 06:56:52 +02:00
committed by GitHub
parent 73b0398d24
commit 5f657478aa
2 changed files with 22 additions and 2 deletions
+4 -2
View File
@@ -142,13 +142,15 @@ export async function fsRoutes<State>(
routePath.slice(0, routePath.lastIndexOf("."))
}`;
const base = normalizedPath.slice(0, normalizedPath.lastIndexOf("/"));
const isMiddleware = normalizedPath.endsWith("/_middleware");
return {
path: normalizedPath,
filePath: routePath,
base,
handlers: mod.handlers ?? mod.handler ?? null,
handlers: mod.handlers ?? mod.handler ??
(isMiddleware ? mod.default ?? null : null),
config: mod.config ?? null,
component: mod.default ?? null,
component: isMiddleware ? null : mod.default ?? null,
} as InternalRoute<State>;
}),
);