Skip to content

Commit 20532fa

Browse files
🚚 chore: add util for getting request data
1 parent cac0a04 commit 20532fa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎utils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function getRequestBody(request) {
2+
return new Promise((resolve, reject) => {
3+
let body = "";
4+
5+
request.on("data", (chunk) => {
6+
body += chunk.toString();
7+
});
8+
9+
request.on("end", () => {
10+
if(!body) return reject();
11+
12+
resolve(JSON.parse(body)); // <--- convert to JSON
13+
});
14+
});
15+
}
16+
17+
module.exports = { getRequestBody };

0 commit comments

Comments
 (0)