Skip to content

Commit

Permalink
feat: 🔊 Fix response payload not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
Hobart2967 committed Oct 3, 2023
1 parent 08379ba commit 5f0aa93
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5f0aa93

Please sign in to comment.