UNPKG

@webfaas/webfaas-plugin-endpoint-http

Version:
83 lines 3.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const path = require("path"); const webfaas_core_1 = require("@webfaas/webfaas-core"); const EndPointHTTPConfig_1 = require("./EndPointHTTPConfig"); const EndPointHTTP_1 = require("./EndPointHTTP"); class WebFassPlugin { constructor(core) { this.endPointHttp = null; this.endPointHttps = null; this.core = core; let itemConfigHTTP = this.core.getConfig().get("endpoint.http", {}); if (!itemConfigHTTP.disabled) { let configHTTP = new EndPointHTTPConfig_1.EndPointHTTPConfig(); configHTTP.type = EndPointHTTPConfig_1.EndPointHTTPConfigTypeEnum.HTTP; configHTTP.port = itemConfigHTTP.port || 8080; configHTTP.hostname = itemConfigHTTP.hostname; configHTTP.httpConfig = itemConfigHTTP.httpConfig || null; configHTTP.route = this.core.getConfig().get("endpoint.http.route", {}); this.endPointHttp = new EndPointHTTP_1.EndPointHTTP(core, configHTTP); } let itemConfigHTTPS = this.core.getConfig().get("endpoint.https", {}); if (!itemConfigHTTPS.disabled) { let configHTTPS = new EndPointHTTPConfig_1.EndPointHTTPConfig(); configHTTPS.type = EndPointHTTPConfig_1.EndPointHTTPConfigTypeEnum.HTTPS; configHTTPS.port = itemConfigHTTPS.port || 8443; configHTTPS.hostname = itemConfigHTTPS.hostname; configHTTPS.httpConfig = itemConfigHTTPS.httpConfig || null; configHTTPS.route = this.core.getConfig().get("endpoint.https.route", {}); if (configHTTPS.httpConfig) { if (configHTTPS.httpConfig.ca) { configHTTPS.httpConfig.ca = this.readCert(configHTTPS.httpConfig.ca.toString()); } if (configHTTPS.httpConfig.cert) { configHTTPS.httpConfig.cert = this.readCert(configHTTPS.httpConfig.cert.toString()); } if (configHTTPS.httpConfig.pfx) { configHTTPS.httpConfig.pfx = this.readCert(configHTTPS.httpConfig.pfx.toString()); } } else { configHTTPS.httpConfig = {}; configHTTPS.httpConfig.pfx = this.readCert(path.join(__dirname, "../ssl", "cert.p12")); configHTTPS.httpConfig.passphrase = "changeit"; } this.endPointHttps = new EndPointHTTP_1.EndPointHTTP(core, configHTTPS); } this.onConfigReload = this.onConfigReload.bind(this); webfaas_core_1.EventManager.addListener(webfaas_core_1.EventManagerEnum.CONFIG_RELOAD, this.onConfigReload); } async startPlugin(core) { if (this.endPointHttp) { await this.endPointHttp.start(); } if (this.endPointHttps) { await this.endPointHttps.start(); } } async stopPlugin() { if (this.endPointHttp) { await this.endPointHttp.stop(); } if (this.endPointHttps) { await this.endPointHttps.stop(); } } readCert(file) { return fs.readFileSync(file); } onConfigReload() { if (this.endPointHttp) { let configHTTP = this.endPointHttp.getConfig(); configHTTP.route = this.core.getConfig().get("endpoint.http.route", {}); } if (this.endPointHttps) { let configHTTPS = this.endPointHttps.getConfig(); configHTTPS.route = this.core.getConfig().get("endpoint.https.route", {}); } } } exports.default = WebFassPlugin; //# sourceMappingURL=WebFassPlugin.js.map