Skip to content

Commit 2ab1490

Browse files
authored
fix(site): answer other methods on pages with a 405 (#63102)
1 parent 98e4b53 commit 2ab1490

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎services/site/src/static/render.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ const answered = (path: string, method: string) =>
5353
*/
5454
export const staticPages: Middleware = async (_event, next) => {
5555
const event = getRequestEvent()
56-
if (import.meta.env.DEV || !event || (event.request.method !== "GET" && event.request.method !== "HEAD"))
57-
return next()
56+
if (import.meta.env.DEV || !event) return next()
5857
const url = new URL(event.request.url)
5958
const path = strip(url.pathname)
59+
// Pages only answer GET and HEAD. Another method on an address no API route or server function serves gets a
60+
// 405, not the app's document, whose scripts production no longer ships.
61+
if (event.request.method !== "GET" && event.request.method !== "HEAD")
62+
return path.startsWith("/_server") || pages.some((route) => !route.page && matches(route.path, path))
63+
? next()
64+
: new Response(null, { status: 405, headers: { Allow: "GET, HEAD" } })
6065
const pattern = staticPath(path) ?? (answered(path, event.request.method) ? undefined : "/*404")
6166
const load =
6267
pattern && pages.find((route) => route.page && route.path.replace(/(.)\/$/, "$1") === pattern)?.$component?.import

0 commit comments

Comments
 (0)