MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / embeddedToStaticRoutes

Function embeddedToStaticRoutes

apps/local/src/serve.ts:92–106  ·  view source on GitHub ↗

* 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>)

Source from the content-addressed store, hash-verified

90 * The embedded map is generated by the CLI build step using `with { type: "file" }`.
91 */
92function embeddedToStaticRoutes(embedded: Record<string, string>): Record<string, StaticHandler> {
93 const routes: Record<string, StaticHandler> = {};
94 for (const [key, bunfsPath] of Object.entries(embedded)) {
95 const file = Bun.file(bunfsPath);
96 routes[`/${key}`] = () =>
97 key === "index.html"
98 ? htmlResponse(file)
99 : new Response(file, {
100 headers: {
101 "content-type": file.type || "application/octet-stream",
102 },
103 });
104 }
105 return routes;
106}
107
108// ---------------------------------------------------------------------------
109// Dev mode: spawn vite as a child and proxy non-API requests to it

Callers 1

startServerFunction · 0.85

Calls 1

htmlResponseFunction · 0.85

Tested by

no test coverage detected