From 5f0aa93921085f6fabf319fbe25f2c5f7fcee268 Mon Sep 17 00:00:00 2001 From: Marco Klein Date: Tue, 3 Oct 2023 13:47:22 +0200 Subject: [PATCH] feat: :loud_sound: Fix response payload not saved --- src/app.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app.ts b/src/app.ts index 142d737..7e4f6d6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -169,14 +169,21 @@ export class App { this._logger.debug(`${prefix} Body received (RAW): ${request.rawBody}`); this._logger.debug(`${prefix} Body received: ${JSON.stringify(request.body)}`); - var data = ""; + var responsePayload = ""; - response.on('data', (chunk) => data += chunk) + const sock = req.socket; + const write = sock.write.bind(sock); + + (sock as any).write = (data: any, encoding: BufferEncoding, callback: any) => { + responsePayload += data; + write(data, encoding, callback); + } + + sock.on('close', () => console.log('DONE')); response.on("finish", () => { this._logger.info(`${prefix} END with ${response.statusCode}`); - this._logger.debug(`${prefix} Headers sent: ${JSON.stringify(response.headersSent)}`); - this._logger.debug(`${prefix} Body sent: ${data}`); + this._logger.debug(`${prefix} Response sent: ${responsePayload}`); }); next();