diff --git a/packages/qwik-city/src/middleware/bun/index.ts b/packages/qwik-city/src/middleware/bun/index.ts index 195f88f09f1..c02483581e5 100644 --- a/packages/qwik-city/src/middleware/bun/index.ts +++ b/packages/qwik-city/src/middleware/bun/index.ts @@ -144,6 +144,15 @@ export function createQwikCity(opts: QwikCityBunOptions) { if (isStaticPath(request.method || 'GET', url)) { const { filePath, content } = await openStaticFile(url); + // We know that it's in the static folder, but it could still be missing + // If we start the stream with a missing file, it will throw a 500 error during the stream + if (!(await content.exists())) { + return new Response('Not Found', { + status: 404, + headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Not-Found': url.pathname }, + }); + } + const ext = extname(filePath).replace(/^\./, ''); return new Response(await content.stream(), {