(res: ServerResponse, status: number, payload: unknown, method: string)
| 114 | |
| 115 | /** Send a JSON response. Used for `/api/*`, which must never get HTML back. */ |
| 116 | export 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. |
no test coverage detected