#Serve Angular with Bun
1 messages · Page 1 of 1 (latest)
Can I see the code
import { serve, spawnSync } from "bun";
import { environment } from "../src/environments/environment.local_stage";
const PORT = 4200; // or any port you prefer
const DIST_DIR = "dist"; // replace with your actual dist directory path
//spawnSync(["bun", "tsc"], { stdio: ["inherit"] });
const result = await Bun.build({
entrypoints: ['src/main.ts'],
root: './',
outdir: DIST_DIR,
target: 'browser',
sourcemap: 'inline',
external: ['chrome'],
define: {
"Bun.env": JSON.stringify(environment)
}
});
serve({
fetch(request) {
// Resolve the file path
const url = new URL(request.url);
let filePath = DIST_DIR + url.pathname;
// Default to index.html for root and any not-found paths (SPA routing)
//if (url.pathname === "/" || !Bun.file(filePath).existsSync()) {
filePath = DIST_DIR + "/index.html";
//}
// Serve the file
return new Response(Bun.file(filePath));
},
port: PORT,
});
console.log(Server is running on http://localhost:${PORT});
@crude jackal there's no existsSync method on Bun.file()