liefern
Version:
Node Webserver without dependencies
32 lines • 762 B
JavaScript
const bodyString = async (request) => {
return new Promise((resolve, reject) => {
try {
const bodyParts = [];
request
.on('data', (chunk) => {
bodyParts.push(chunk);
})
.on('end', () => {
resolve(Buffer.concat(bodyParts).toString());
});
}
catch (error) {
reject(error);
}
});
};
export const body = async (request) => {
try {
const text = await bodyString(request);
try {
return JSON.parse(text);
}
catch (error) {
return text;
}
}
catch (error) {
return undefined;
}
};
//# sourceMappingURL=bodyHelper.js.map