Skip to content

Commit 46e83d1

Browse files
committed
Fix body parser
1 parent a0d9521 commit 46e83d1

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

JavaScript/1-HTTP/server.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,12 @@ setTimeout(() => {
4646
console.dir({ api });
4747
}, 1000);
4848

49-
const receiveArgs = async (req) => new Promise((resolve) => {
50-
const body = [];
51-
req.on('data', (chunk) => {
52-
body.push(chunk);
53-
}).on('end', async () => {
54-
const data = body.join('');
55-
const args = JSON.parse(data);
56-
resolve(args);
57-
});
58-
});
49+
const receiveArgs = async (req) => {
50+
const buffers = [];
51+
for await (const chunk of req) buffers.push(chunk);
52+
const data = Buffer.concat(buffers).toString();
53+
return JSON.parse(data);
54+
};
5955

6056
const httpError = (res, status, message) => {
6157
res.statusCode = status;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy