Initial commit: Bun + React + Tailwind + shadcn setup
This commit is contained in:
37
server.ts
Normal file
37
server.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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");
|
||||
Reference in New Issue
Block a user