* Convert an embedded web UI map (path → bunfs path) into Bun.serve routes. * The embedded map is generated by the CLI build step using `with { type: "file" }`.
(embedded: Record<string, string>)
| 84 | * The embedded map is generated by the CLI build step using `with { type: "file" }`. |
| 85 | */ |
| 86 | function embeddedToStaticRoutes(embedded: Record<string, string>): Record<string, StaticHandler> { |
| 87 | const routes: Record<string, StaticHandler> = {}; |
| 88 | for (const [key, bunfsPath] of Object.entries(embedded)) { |
| 89 | const file = Bun.file(bunfsPath); |
| 90 | routes[`/${key}`] = () => |
| 91 | key === "index.html" |
| 92 | ? htmlResponse(file) |
| 93 | : new Response(file, { |
| 94 | headers: { |
| 95 | "content-type": file.type || "application/octet-stream", |
| 96 | }, |
| 97 | }); |
| 98 | } |
| 99 | return routes; |
| 100 | } |
| 101 | |
| 102 | // --------------------------------------------------------------------------- |
| 103 | // Dev mode: spawn vite as a child and proxy non-API requests to it |
no test coverage detected