MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / serveFile

Function serveFile

ts/workflow-cli/server/staticServer.ts:85–97  ·  view source on GitHub ↗

Write `file` to the response with a guessed content type. Returns false if it doesn't exist.

(res: ServerResponseLike, file: string)

Source from the content-addressed store, hash-verified

83
84/** Write `file` to the response with a guessed content type. Returns false if it doesn't exist. */
85async function serveFile(res: ServerResponseLike, file: string): Promise<boolean> {
86 try {
87 const content = await fs.readFile(file);
88 res.setHeader("Content-Type", MIME[path.extname(file).toLowerCase()] ?? "application/octet-stream");
89 res.end(content);
90 return true;
91 } catch (err: unknown) {
92 if ((err as NodeJS.ErrnoException).code === "ENOENT") return false;
93 res.statusCode = 500;
94 res.end((err as NodeJS.ErrnoException).code ?? "read failed");
95 return true;
96 }
97}
98
99// Minimal structural type so this helper isn't tied to the full http types.
100type ServerResponseLike = {

Callers 1

startStaticServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected