Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions static-server.js
Original file line number Diff line number Diff line change
@@ -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")