Skip to content

Commit

Permalink
feat: Add body parsing for POST, PATCH, PUT requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Feb 28, 2024
1 parent 9a97e64 commit c4cf5e8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/server/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class HttpServer {
) {
const startTime = performance.now();
let index = 0;
let body = '';

res.on('finish', () => {
const finishTime = performance.now();
Expand All @@ -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);
};

Expand Down

0 comments on commit c4cf5e8

Please sign in to comment.