@decisions/api-helpers
Version:
JavaScript toolkit for REST, etc. for external UIs using Decisions as a back-end.
42 lines • 1.43 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var DEFAULT_ROOT = "../decisions/Primary/";
/**
* Config object. Depends on either a `DecisionsRestConfig` variable defined on the
* global namespace, or `rest-config.json` at the same path as the application.
*/
exports.ApiConfig = {
cors: true,
getFetchMode: function () {
return this.cors ? "cors" : "same-origin";
},
isLoaded: false,
loadConfig: function () {
var _this = this;
// check for it on the global namespace:
if (!!DecisionsRestConfig) {
this.cors = DecisionsRestConfig.cors;
this.restRoot = DecisionsRestConfig.restRoot;
return;
}
// if it wasn't there, try to load it:
fetch("./rest-config.json")
.then(function (value) {
return value
.json()
.then(function (json) {
_this.restRoot = json.restRoot;
_this.cors = json.cors;
_this.isLoaded = true;
})
.catch(logRootConfigLoadError);
})
.catch(logRootConfigLoadError);
},
restRoot: DEFAULT_ROOT,
};
function logRootConfigLoadError(reason) {
// tslint:disable-next-line:no-console
console.error("failed to load rest-root", reason);
}
//# sourceMappingURL=ApiConfig.js.map
;