diff --git a/backend/src/index.ts b/backend/src/index.ts index 8679d45..2e9a36a 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -3,6 +3,8 @@ import { cors } from "@elysiajs/cors"; import { videoRoutes } from "./routes/videos"; import { initDb } from "./services/db"; import { renderRunPage, getOembed } from "./embeds"; +import { join } from "path"; +import { existsSync, statSync } from "fs"; initDb(); @@ -29,6 +31,19 @@ const app = new Elysia() headers: { "Content-Type": result.contentType }, }); }) + .get("*", ({ request }) => { + const url = new URL(request.url); + const pathname = url.pathname; + + const filePath = join(STATIC_DIR, pathname); + if (existsSync(filePath) && statSync(filePath).isFile()) + return Bun.file(filePath); + + const indexPath = join(STATIC_DIR, "index.html"); + if (existsSync(indexPath)) return Bun.file(indexPath); + + return status(404, "Not found"); + }) .listen(PORT); console.log(`surf.nathan.rip running on port ${PORT}`);