fix: HEAD when only GET is registered in .route() (#3587)

This commit is contained in:
Marvin Hagemeister
2025-10-30 14:59:12 +01:00
committed by GitHub
parent c7af11eb7c
commit 7fcae1d895
3 changed files with 34 additions and 6 deletions
+11 -4
View File
@@ -4,7 +4,7 @@ import { type Method, patternToSegments } from "./router.ts";
import type { LayoutConfig, Route } from "./types.ts";
import { type Context, getInternals } from "./context.ts";
import { recordSpanError, tracer } from "./otel.ts";
import { isHandlerByMethod } from "./handlers.ts";
import { type HandlerFn, isHandlerByMethod } from "./handlers.ts";
import {
type AsyncAnyComponent,
type PageProps,
@@ -167,9 +167,16 @@ export async function renderRoute<State>(
attributes: { "fresh.span_type": "fs_routes/handler" },
}, async (span) => {
try {
const fn = isHandlerByMethod(handlers)
? handlers[method] ?? null
: handlers;
let fn: HandlerFn<unknown, State> | null = null;
if (isHandlerByMethod(handlers)) {
if (handlers[method] !== undefined) {
fn = handlers[method];
} else if (method === "HEAD" && handlers.GET !== undefined) {
fn = handlers.GET;
}
} else {
fn = handlers;
}
if (fn === null) return await ctx.next();