MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / sendJson

Function sendJson

src/ui-server/static.ts:116–124  ·  view source on GitHub ↗
(res: ServerResponse, status: number, payload: unknown, method: string)

Source from the content-addressed store, hash-verified

114
115/** Send a JSON response. Used for `/api/*`, which must never get HTML back. */
116export function sendJson(res: ServerResponse, status: number, payload: unknown, method: string): void {
117 const body = Buffer.from(JSON.stringify(payload), 'utf-8');
118 res.writeHead(status, {
119 'Content-Type': 'application/json; charset=utf-8',
120 'Content-Length': String(body.byteLength),
121 'Cache-Control': 'no-store',
122 });
123 res.end(method === 'HEAD' ? undefined : body);
124}
125
126/**
127 * Whether a request path should fall back to `index.html` when no file matches.

Callers 3

handleRequestFunction · 0.90
okFunction · 0.90
failFunction · 0.90

Calls 1

fromMethod · 0.80

Tested by

no test coverage detected