Re-add static file serving catch-all route
This commit is contained in:
@@ -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}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user