Files
schlaustronics-website/server.ts

37 lines
829 B
TypeScript

import { serve } from "bun";
import { join } from "path";
const DIST_DIR = "./dist";
serve({
port: 3000,
hostname: "0.0.0.0",
async fetch(req) {
const url = new URL(req.url);
let path = url.pathname;
// Default to index.html
if (path === "/") {
path = "/index.html";
}
const filePath = join(DIST_DIR, path);
try {
const file = Bun.file(filePath);
const exists = await file.exists();
if (exists) {
return new Response(file);
}
// For SPA routing, fall back to index.html
const indexFile = Bun.file(join(DIST_DIR, "index.html"));
return new Response(indexFile);
} catch (error) {
return new Response("Not Found", { status: 404 });
}
},
});
console.log("Server running at http://0.0.0.0:3000");