@mvx/mvc
Version:
@mvx/mvc is mvc framework on server, base on koa, @tsdi frameworks
80 lines (78 loc) • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MvcServer = void 0;
const tslib_1 = require("tslib");
const ioc_1 = require("@tsdi/ioc");
const boot_1 = require("@tsdi/boot");
const Router_1 = require("./router/Router");
const https = require("https");
/**
* base mvc server.
*
* @export
* @abstract
* @class MvcServer
* @implements {IMvcServer}
*/
let MvcServer = class MvcServer extends boot_1.Service {
/**
* configure startup service.
*
* @param {IBootContext} [ctx]
* @returns {(Promise<void>)}
* @memberof IStartup
*/
async configureService(ctx) {
this.context = ctx;
let config = ctx.getConfiguration();
this.logger = ctx.getLogManager().getLogger();
this.port = config.port || parseInt(process.env.PORT || '0');
this.hostname = config.hostname;
this.uri = `${ctx.httpServer instanceof https.Server ? 'https' : 'http'}://${this.hostname || '127.0.0.1'}:${this.port}`;
}
getContext() {
return this.context;
}
getConfig() {
return this.context.getConfiguration();
}
getRouter() {
return this.router;
}
getHttpServer() {
return this.getContext().httpServer;
}
async start() {
let ctx = this.getContext();
let listener = ctx.listener;
let server = this.getHttpServer();
if (this.hostname) {
server.listen(this.port, this.hostname, listener);
}
else {
server.listen(this.port, listener);
}
this.logger.info('mvc service start: ', this.uri);
}
async stop() {
let httpServer = this.getHttpServer();
if (httpServer) {
this.logger.info('close mvc http(s) service');
httpServer.removeAllListeners();
httpServer.close();
}
}
static ρAnn() {
return { "name": "MvcServer", "params": { "configureService": ["ctx"] } };
}
};
tslib_1.__decorate([
ioc_1.Inject(),
tslib_1.__metadata("design:type", Router_1.Router)
], MvcServer.prototype, "router", void 0);
MvcServer = tslib_1.__decorate([
ioc_1.Injectable(),
ioc_1.Refs('@MvcModule', boot_1.Startup)
], MvcServer);
exports.MvcServer = MvcServer;
//# sourceMappingURL=sourcemaps/MvcServer.js.map