feat: add default GET handler (#2542)

closes https://github.com/denoland/fresh/issues/2530
This commit is contained in:
Reed von Redwitz
2024-06-24 15:04:21 +02:00
committed by GitHub
parent 77bd7d0d44
commit a560c17e7b
2 changed files with 72 additions and 4 deletions
+10 -4
View File
@@ -284,14 +284,20 @@ export async function fsRoutes<State>(
}
}
if (routeMod.component !== null) {
components.push(routeMod.component);
}
const handlers = routeMod.handlers;
const routePath = routeMod.config?.routeOverride ??
pathToPattern(normalized.slice(1));
if (routeMod.component !== null) {
components.push(routeMod.component);
const missingGetHandler = handlers !== null &&
isHandlerByMethod(handlers) &&
!Object.keys(handlers).includes("GET");
if (missingGetHandler) {
app.get(routePath, renderMiddleware(components, undefined));
}
}
if (
handlers === null ||
(isHandlerByMethod(handlers) && Object.keys(handlers).length === 0)