zents
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
46 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Server = void 0;
const IncomingRequest_1 = require("./IncomingRequest");
const config_1 = require("../config/config");
const http_1 = require("http");
const https_1 = require("https");
class Server {
constructor(registry) {
const securityProviders = registry.getSecurityProviders();
this.controllers = registry.getControllers();
this.router = registry.factories.router.generate(this.controllers, securityProviders,
// eslint-disable-next-line @typescript-eslint/no-misused-promises
async (config, route, req, res, params) => {
const incomingRequest = new IncomingRequest_1.IncomingRequest();
await incomingRequest.handle(registry.factories.request, route, req, res, params, config, securityProviders);
});
}
listen(...args) {
const server = !config_1.config.web.https.enable
? http_1.createServer(this.createRequestHandler())
: this.createHttpsServer();
return server.listen(...args);
}
createRequestHandler() {
const handler = (req, res) => this.router.lookup(req, res);
return handler;
}
createHttpsServer() {
var _a, _b, _c, _d;
const usePem = typeof ((_b = (_a = config_1.config.web) === null || _a === void 0 ? void 0 : _a.https) === null || _b === void 0 ? void 0 : _b.key) !== 'undefined' &&
typeof ((_d = (_c = config_1.config.web) === null || _c === void 0 ? void 0 : _c.https) === null || _d === void 0 ? void 0 : _d.cert) !== 'undefined';
const options = usePem
? {
key: config_1.config.web.https.key,
cert: config_1.config.web.https.cert,
}
: {
pfx: config_1.config.web.https.pfx,
passphrase: config_1.config.web.https.passphrase,
};
return https_1.createServer(options, this.createRequestHandler());
}
}
exports.Server = Server;
//# sourceMappingURL=Server.js.map