From c4cf5e8a922af0aed18f7f2ee004e80d1d40beae Mon Sep 17 00:00:00 2001 From: ck <21735205+cyperdark@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:19:19 +0300 Subject: [PATCH] feat: Add body parsing for POST, PATCH, PUT requests --- packages/server/utils/http.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/server/utils/http.ts b/packages/server/utils/http.ts index d9f5313a..109c761c 100644 --- a/packages/server/utils/http.ts +++ b/packages/server/utils/http.ts @@ -69,6 +69,7 @@ export class HttpServer { ) { const startTime = performance.now(); let index = 0; + let body = ''; res.on('finish', () => { const finishTime = performance.now(); @@ -87,6 +88,19 @@ export class HttpServer { return; } + // get data aka body + if (['POST', 'PUT', 'PATCH'].includes(req.method || '')) { + req.on('data', (chunk) => { + body += chunk; + }); + + req.on('end', () => { + req.body = body; + + this.handleNext(req, res); + }); + return; + } this.handleNext(req, res); };