springboot-express
Version:
express-spring-boot
89 lines • 3.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpressSpringApp = void 0;
const logger20js_ts_1 = require("logger20js-ts");
const Properties_1 = require("lib-utils-ts/src/file/Properties");
const MiddleWare_1 = require("./MiddleWare");
const https = require("https");
const Application_1 = require("./Application");
class ExpressSpringApp {
constructor(properties = null) {
this.applicationWrap = Application_1.Application.getInstance();
this.prop = Application_1.Application.getInstance().getProperties();
this.baseUrl = "/v1";
this.mockUserAccess = -1;
if (properties) {
this.prop = properties;
this.baseUrl = properties.getProperty("baseUrl", null);
}
else if (!this.prop) {
this.prop = new Properties_1.Properties();
this.prop.setProperty("httpProtocol", true);
this.prop.setProperty("httpProtocol", false);
this.prop.setProperty("gateway", "gateway");
this.prop.setProperty("loggerParser ", 80);
this.prop.setProperty("loggerParser", "[%hours{yellow}] %T{w?yellow;e?red;d?green}/%name - %error");
this.prop.setProperty("logEnabledColorize", true);
this.prop.setProperty("saveLog", false);
}
this.middleWare = new MiddleWare_1.MiddleWare(this);
}
setBaseUrl(baseUrl) {
this.baseUrl = baseUrl;
return this;
}
getBaseUrl() { return String(this.prop.getProperty("gateway", this.baseUrl)); }
setMockDefaultUserAccess(level) {
this.mockUserAccess = level;
return this;
}
getMockDefaultUserAccess() {
return this.mockUserAccess;
}
getApp() { return this.applicationWrap.getApp(); }
getMiddleWare() { return this.middleWare; }
loadProperties(path) {
this.applicationWrap.loadConfiguration(path);
this.prop = this.applicationWrap.getProperties();
return this;
}
config() { throw new Error("Not implemented !"); }
initPages() {
this.applicationWrap.init(String(this.prop.getProperty("pagesDirectory")));
return this;
}
getSSlOpts() {
let sslOpts = {};
if (this.prop.getProperty("sslPfx", null)) {
sslOpts.pfx = String(this.prop.getProperty("sslPfx"));
sslOpts.passphrase = String(this.prop.getProperty("sslPassphrase"));
}
else {
sslOpts.cert = String(this.prop.getProperty("sslCert"));
sslOpts.key = String(this.prop.getProperty("sslCertKey"));
}
if (this.prop.getProperty("sslCacert"))
sslOpts.cacert = String(this.prop.getProperty("sslCacert"));
return sslOpts;
}
sslProtocol() {
if (Boolean.of(this.prop.getProperty("httpsProtocol"))) {
let port = Number(this.prop.getProperty("sslPort", 80)), gateway = String(this.prop.getProperty("gateway", "0.0.0.0")), sslOpts = {};
https.createServer(this.getSSlOpts(), this.getApp()).listen(port, gateway, 1, () => {
ExpressSpringApp.logger.info("SSL/TLS server has been started : %s:%s", gateway, port);
});
}
}
listen() {
if (Boolean.of(this.prop.getProperty("httpProtocol"))) {
let port = Number(this.prop.getProperty("port", 80)), gateway = String(this.prop.getProperty("gateway", "0.0.0.0"));
this.getApp().listen(port, gateway, () => {
ExpressSpringApp.logger.info("server has been started : %s:%s", gateway, port);
});
}
return this.sslProtocol();
}
}
exports.ExpressSpringApp = ExpressSpringApp;
ExpressSpringApp.logger = logger20js_ts_1.Logger.factory(Application_1.Application.name);
//# sourceMappingURL=ExpressSpringApp.js.map