Skip to content

Commit a59eae1

Browse files
committed
fix: forward headers and restrict methods in enableFallback mode
- Forward request headers to serveStaticFile to enable 304 caching - Restrict static file serving to GET/HEAD methods only - Prevents unexpected behavior with POST/PUT/DELETE requests
1 parent e033522 commit a59eae1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({
297297
app.onError({ as: 'global' }, async ({ code, request }) => {
298298
if (code !== 'NOT_FOUND') return
299299

300+
// Only serve static files for GET/HEAD
301+
if (request.method !== 'GET' && request.method !== 'HEAD') return
302+
300303
const url = new URL(request.url)
301304
let pathname = url.pathname
302305

@@ -316,7 +319,8 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({
316319
)
317320

318321
try {
319-
return await serveStaticFile(pathName)
322+
const headers = Object.fromEntries(request.headers)
323+
return await serveStaticFile(pathName, headers)
320324
} catch {
321325
return
322326
}

0 commit comments

Comments
 (0)