(dir: string, prefix = "")
| 55 | ); |
| 56 | |
| 57 | function collectStaticRoutes(dir: string, prefix = ""): Record<string, StaticHandler> { |
| 58 | const routes: Record<string, StaticHandler> = {}; |
| 59 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: filesystem route discovery is best-effort for optional built assets |
| 60 | try { |
| 61 | for (const entry of readdirSync(dir, { withFileTypes: true })) { |
| 62 | const fullPath = join(dir, entry.name); |
| 63 | const routePath = `${prefix}/${entry.name}`; |
| 64 | if (entry.isDirectory()) { |
| 65 | Object.assign(routes, collectStaticRoutes(fullPath, routePath)); |
| 66 | } else { |
| 67 | const file = Bun.file(fullPath); |
| 68 | routes[routePath] = () => |
| 69 | routePath === "/index.html" |
| 70 | ? htmlResponse(file) |
| 71 | : new Response(file, { |
| 72 | headers: { |
| 73 | "content-type": file.type || "application/octet-stream", |
| 74 | }, |
| 75 | }); |
| 76 | } |
| 77 | } |
| 78 | } catch {} |
| 79 | return routes; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Convert an embedded web UI map (path → bunfs path) into Bun.serve routes. |
no test coverage detected