-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.ts
More file actions
37 lines (29 loc) 路 1 KB
/
Copy pathserve.ts
File metadata and controls
37 lines (29 loc) 路 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { serve } from "bun";
import { join } from "node:path";
const PORT = parseInt(process.env.INGRESS_PORT || "3000", 10);
const HOST = process.env.INGRESS_HOST || "0.0.0.0";
const ROOT = "./dist";
serve({
port: PORT,
hostname: HOST,
async fetch(req) {
const url = new URL(req.url);
let path = url.pathname;
// Strip ingress base path (X-Ingress-Path header) if present
const ingressPath = req.headers.get("x-ingress-path");
if (ingressPath && path.startsWith(ingressPath)) {
path = path.slice(ingressPath.length) || "/";
}
// Default to index.html
if (path === "/" || path === "") {
path = "/index.html";
}
const filePath = join(ROOT, path);
const file = Bun.file(filePath);
if (await file.exists()) {
return new Response(file);
}
return new Response("Not found", { status: 404 });
},
});
console.log(`馃尡 Prompts running at http://${HOST}:${PORT}`);