(request: IncomingMessage)
| 105 | const decodeJsonBody = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown)); |
| 106 | |
| 107 | const readJsonBody = async (request: IncomingMessage): Promise<unknown> => { |
| 108 | const chunks: Buffer[] = []; |
| 109 | for await (const chunk of request) { |
| 110 | chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); |
| 111 | } |
| 112 | const body = Buffer.concat(chunks).toString("utf8"); |
| 113 | return body ? decodeJsonBody(body) : null; |
| 114 | }; |
| 115 | |
| 116 | const writeJson = (response: ServerResponse, status: number, body: unknown): void => { |
| 117 | response.writeHead(status, { "content-type": "application/json" }); |
no test coverage detected