inference-server
Version:
Libraries and server to build AI applications. Adapters to various native bindings allowing local inference. Integrate it with your application, or use as a microservice.
24 lines • 677 B
JavaScript
export function parseJSONRequestBody(req) {
return new Promise((resolve, reject) => {
// if request is from express theres no need to parse anything
if ('body' in req) {
resolve(req.body);
return;
}
// for native http server
let body = '';
req.on('data', (chunk) => {
body += chunk.toString();
});
req.on('end', () => {
try {
const data = JSON.parse(body);
resolve(data);
}
catch (error) {
reject(error);
}
});
});
}
//# sourceMappingURL=parseJSONRequestBody.js.map