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

Function collectStaticRoutes

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

Source from the content-addressed store, hash-verified

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