(req: HTTPRequestLike)
| 69 | } |
| 70 | |
| 71 | export function parseJSONBody(req: HTTPRequestLike): Promise<Record<string, unknown>> { |
| 72 | return new Promise((resolve, reject) => { |
| 73 | let body = ""; |
| 74 | req.on("data", (chunk: string | { toString(): string }) => { |
| 75 | body += chunk.toString(); |
| 76 | }); |
| 77 | req.on("end", () => { |
| 78 | try { |
| 79 | resolve(body ? JSON.parse(body) : {}); |
| 80 | } catch { |
| 81 | reject(new Error("Invalid JSON")); |
| 82 | } |
| 83 | }); |
| 84 | req.on("error", reject); |
| 85 | }); |
| 86 | } |
no test coverage detected