MCPcopy Create free account
hub / github.com/ReviewStage/stage-cli / sendFile

Function sendFile

packages/cli/src/server.ts:201–219  ·  view source on GitHub ↗
(filePath: string, res: http.ServerResponse)

Source from the content-addressed store, hash-verified

199}
200
201async function sendFile(filePath: string, res: http.ServerResponse): Promise<boolean> {
202 let stat: Awaited<ReturnType<typeof fsp.stat>>;
203 try {
204 stat = await fsp.stat(filePath);
205 } catch (err) {
206 const code = (err as NodeJS.ErrnoException).code;
207 if (code === "ENOENT" || code === "ENOTDIR") return false;
208 throw err;
209 }
210 if (!stat.isFile()) return false;
211
212 const ext = path.extname(filePath).toLowerCase();
213 res.writeHead(200, {
214 "Content-Type": MIME_TYPES[ext] ?? "application/octet-stream",
215 "Content-Length": String(stat.size),
216 });
217 await pipeline(createReadStream(filePath), res);
218 return true;
219}
220
221async function sendIndexFallback(webDist: string, res: http.ServerResponse): Promise<void> {
222 const indexPath = path.join(webDist, "index.html");

Callers 1

handleRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected