vulcain-corejs
Version:
Vulcain micro-service framework
85 lines (83 loc) • 3.37 kB
JavaScript
const fs = require("fs");
const system_1 = require("./../configurations/globals/system");
/**
* Conventions values
* You can override this values before instanciating application
*
* @export
* @class Conventions
*/
class Conventions {
constructor() {
/**
* Naming
*
*/
this.defaultApplicationFolder = "/api";
this.defaultHystrixPath = "/hystrix.stream";
this.defaultUrlprefix = "/api";
this.vulcainFileName = ".vulcain";
this.defaultStatsdDelayInMs = 10000;
this.defaultSecretKey = "DnQBnCG7*fjEX@Rw5uN^hWR4*AkRVKMeRu2#Ucu^ECUNWrKr";
this.defaultTokenExpiration = "20m";
this.VULCAIN_SECRET_KEY = "vulcainSecretKey";
this.TOKEN_ISSUER = "vulcainTokenIssuer";
this.TOKEN_EXPIRATION = "vulcainTokenExpiration";
this.ENV_VULCAIN_TENANT = "VULCAIN_TENANT";
this.ENV_VULCAIN_ENV = "VULCAIN_ENV"; // staging, prod, test...
this.ENV_VULCAIN_DOMAIN = "VULCAIN_DOMAIN";
this.ENV_SERVICE_NAME = "VULCAIN_SERVICE_NAME";
this.ENV_SERVICE_VERSION = "VULCAIN_SERVICE_VERSION";
this.ENV_VULCAIN_ENV_MODE = "VULCAIN_ENV_MODE"; // 'production', 'test' or 'local'
this.hystrix = {
"hystrix.health.snapshot.validityInMilliseconds": 500,
"hystrix.force.circuit.open": false,
"hystrix.force.circuit.closed": false,
"hystrix.circuit.enabled": true,
"hystrix.circuit.sleepWindowInMilliseconds": 5000,
"hystrix.circuit.errorThresholdPercentage": 50,
"hystrix.circuit.volumeThreshold": 10,
"hystrix.execution.timeoutInMilliseconds": 1500,
"hystrix.metrics.statistical.window.timeInMilliseconds": 10000,
"hystrix.metrics.statistical.window.bucketsNumber": 10,
"hystrix.metrics.percentile.window.timeInMilliseconds": 10000,
"hystrix.metrics.percentile.window.bucketsNumber": 10,
"hystrix.isolation.semaphore.maxConcurrentRequests": 10,
"hystrix.fallback.semaphore.maxConcurrentRequests": 10
};
}
static deepAssign(from, target) {
from && Object.keys(from).forEach(k => {
if (typeof from === "Object") {
target[k] = target[k] || {};
Conventions.deepAssign(from[k], target[k]);
}
else
target[k] = from[k];
});
}
static get instance() {
if (!Conventions._instance) {
Conventions._instance = new Conventions();
try {
if (fs.existsSync("vulcain.conventions")) {
const data = JSON.parse(fs.readFileSync("vulcain.conventions", "utf8"));
Conventions.deepAssign(data, Conventions._instance);
}
}
catch (e) {
system_1.System.log.error(null, e, "Error when reading vulcain.conventions file. Custom conventions are ignored.");
}
}
return Conventions._instance;
}
static toEnvironmentVariableName(name) {
const regex = /([A-Z])|(\.)/g;
const subst = `_\$1`;
let res = name.replace(regex, subst);
return res.toUpperCase();
}
}
exports.Conventions = Conventions;
//# sourceMappingURL=conventions.js.map
;