8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a0d9521 commit 46e83d1Copy full SHA for 46e83d1
JavaScript/1-HTTP/server.js
@@ -46,16 +46,12 @@ setTimeout(() => {
46
console.dir({ api });
47
}, 1000);
48
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
-});
+const receiveArgs = async (req) => {
+ const buffers = [];
+ for await (const chunk of req) buffers.push(chunk);
+ const data = Buffer.concat(buffers).toString();
+ return JSON.parse(data);
+};
59
60
const httpError = (res, status, message) => {
61
res.statusCode = status;
0 commit comments