Re-add static file serving catch-all route

This commit is contained in:
CallMeVerity
2026-06-04 22:47:25 +01:00
parent 32e13fcc85
commit 87e408f1a7
+15
View File
@@ -3,6 +3,8 @@ import { cors } from "@elysiajs/cors";
import { videoRoutes } from "./routes/videos"; import { videoRoutes } from "./routes/videos";
import { initDb } from "./services/db"; import { initDb } from "./services/db";
import { renderRunPage, getOembed } from "./embeds"; import { renderRunPage, getOembed } from "./embeds";
import { join } from "path";
import { existsSync, statSync } from "fs";
initDb(); initDb();
@@ -29,6 +31,19 @@ const app = new Elysia()
headers: { "Content-Type": result.contentType }, 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); .listen(PORT);
console.log(`surf.nathan.rip running on port ${PORT}`); console.log(`surf.nathan.rip running on port ${PORT}`);