ng-apimock-with-presets
Version:
An ng-apimock fork with preset functionality
35 lines • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var http_1 = require("../../http");
var ApplyPresetHandler = (function () {
function ApplyPresetHandler() {
}
ApplyPresetHandler.prototype.handleRequest = function (request, response, next, registry, ngApimockId) {
var _this = this;
var requestDataChunks = [];
request.on('data', function (rawData) {
requestDataChunks.push(rawData);
});
request.on('end', function () {
var data = JSON.parse(Buffer.concat(requestDataChunks).toString());
try {
var match = registry.presets.find(function (_preset) { return _preset.name === data.preset; });
if (match) {
_this.handlePresetSelection(registry, match, ngApimockId);
}
else {
throw new Error('No preset matching identifier [' + data + '] found');
}
response.writeHead(200, http_1.httpHeaders.CONTENT_TYPE_APPLICATION_JSON);
response.end();
}
catch (e) {
response.writeHead(409, http_1.httpHeaders.CONTENT_TYPE_APPLICATION_JSON);
response.end(JSON.stringify(e, ['message']));
}
});
};
return ApplyPresetHandler;
}());
exports.default = ApplyPresetHandler;
//# sourceMappingURL=applyPresetHandler.js.map