fix : 404 error fix

This commit is contained in:
syntaxbullet
2026-01-08 21:45:53 +01:00
parent 39e405afde
commit cf4c28e1df

View File

@@ -213,11 +213,24 @@ export async function createWebServer(config: WebServerConfig = {}): Promise<Web
// SPA Fallback: Serve index.html for unknown non-file routes
const parts = pathName.split("/");
const lastPart = parts[parts.length - 1];
if (lastPart?.includes(".")) {
// If it's a direct request for a missing file (has dot), return 404
// EXCEPT for index.html which is our fallback entry point
if (lastPart?.includes(".") && lastPart !== "index.html") {
return new Response("Not Found", { status: 404 });
}
const indexFile = Bun.file(join(distDir, "index.html"));
if (!(await indexFile.exists())) {
if (isDev) {
return new Response("<html><body><h1>🛠️ Dashboard is building...</h1><p>Please refresh in a few seconds. The bundler is currently generating the static assets.</p><script>setTimeout(() => location.reload(), 2000);</script></body></html>", {
status: 503,
headers: { "Content-Type": "text/html" }
});
}
return new Response("Dashboard Not Found", { status: 404 });
}
let indexHtml = await indexFile.text();
const { env: sharedEnv } = await import("@shared/lib/env");
const script = `<script>window.AURORA_ENV = { ADMIN_TOKEN: "${sharedEnv.ADMIN_TOKEN}" };</script>`;