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

Function collectStaticRoutes

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

Source from the content-addressed store, hash-verified

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