@equinor/fusion-framework-cli
Version:
--- title: Fusion Framework CLI ---
28 lines • 1.44 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
/**
* Extracts and parses JSON data from an incoming HTTP request.
*
* @param req - The incoming HTTP request object.
* @returns A promise that resolves to a record containing the parsed JSON data.
* @throws Will reject the promise if there is an error during data reception or JSON parsing.
*/
export function parseJsonFromRequest(req) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Promise((resolve, reject) => {
let data = '';
req.on('data', (chunk) => (data += chunk.toString()));
req.on('end', () => resolve(JSON.parse(data)));
req.on('error', reject);
});
});
}
export default parseJsonFromRequest;
//# sourceMappingURL=parse-json-request.js.map