Add SPA fallback to serve index.html for unmatched paths

This commit is contained in:
Chris Wanstrath 2026-07-23 11:57:25 -07:00
parent 91424230c7
commit bf15bc3a3c

View File

@ -33,6 +33,12 @@ export async function serveStatic(appName: string, req: Request): Promise<Respon
return new Response(Bun.file(htmlPath))
}
// SPA fallback: serve root index.html for unmatched paths
const rootIndex = join(pubDir, 'index.html')
if (existsSync(rootIndex)) {
return new Response(Bun.file(rootIndex))
}
return new Response('Not Found', { status: 404 })
}