diff --git a/frontend/index.js b/frontend/index.js index 1a3fd8cb0b..1d08af6fea 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -10,21 +10,21 @@ Bun.serve({ console.log("Resolved file path:", filePath); try { - // Check if the requested URL is the root - if (url.pathname === "/") { - // If root, serve the index.html file + // Check if the requested file exists + const fileExists = await Bun.file.exists(filePath); + if (fileExists) { + // If the file exists, serve it + const file = Bun.file(filePath); + return new Response(file); + } else { + // If the file doesn't exist, serve the index.html file const indexFilePath = BASE_PATH + "/index.html"; const indexFile = Bun.file(indexFilePath); return new Response(indexFile); - } else { - // Otherwise, attempt to fetch the file - const file = Bun.file(filePath); - // Return the file if it exists - return new Response(file); } } catch (error) { console.error("Error occurred while fetching file:", error); - // If the file doesn't exist, serve the index.html file + // If any error occurs, serve the index.html file const indexFilePath = BASE_PATH + "/index.html"; const indexFile = Bun.file(indexFilePath); return new Response(indexFile);