diff --git a/static-server.js b/static-server.js new file mode 100644 index 0000000..f2b05b5 --- /dev/null +++ b/static-server.js @@ -0,0 +1,31 @@ +import { serve } from "bun" + +const DIST = "dist" +const BASE = "/app" + +serve({ + port: 4175, + fetch(req) { + const url = new URL(req.url) + + if (!url.pathname.startsWith(BASE)) { + return new Response("Not Found", { status: 404 }) + } + + let filePath = url.pathname.slice(BASE.length) + if (filePath === "" || filePath === "/") { + filePath = "/index.html" + } + + const file = Bun.file(DIST + filePath) + + // SPA fallback + if (!file.size) { + return new Response(Bun.file(DIST + "/index.html")) + } + + return new Response(file) + }, +}) + +console.log("App running on port 4175")