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

Function collectStaticRoutes

apps/local/src/serve.ts:57–80  ·  view source on GitHub ↗
(dir: string, prefix = "")

Source from the content-addressed store, hash-verified

55 );
56
57function 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.

Callers 1

startServerFunction · 0.85

Calls 1

htmlResponseFunction · 0.85

Tested by

no test coverage detected