microframe-ts
Version:
Typescript framework for creating microservices.
59 lines • 2.29 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiManager = void 0;
var express_1 = require("express");
var express = require("express");
var log_1 = require("../log");
var cors = require("cors");
/**
* Manages an Express Application, and API Controllers.
*/
var ApiManager = /** @class */ (function () {
function ApiManager(port, controllers) {
this.app = express();
this.logger = (0, log_1.UseLogger)();
this.port = port;
this.InitMiddleware();
this.controllers = controllers;
this.InitControllers();
}
/**
* Triggers the Express Application to start listening for requests.
*/
ApiManager.prototype.Listen = function () {
var _this = this;
try {
this.app.listen(this.port, function () {
_this.logger.info("Express server has started at http://localhost:".concat(_this.port));
});
}
catch (e) {
this.logger.error("Failed to listen on port ".concat(this.port, " with exception ").concat(e));
}
};
ApiManager.prototype.InitMiddleware = function () {
this.app.use((0, express_1.urlencoded)({ extended: true }));
this.app.use((0, express_1.json)({ verify: function (req, _, buf) { req.rawBody = buf; } }));
this.app.use(cors());
};
ApiManager.prototype.InitControllers = function () {
var _this = this;
this.controllers.forEach(function (controller) {
_this.app.use('/', controller.router);
});
};
return ApiManager;
}());
exports.ApiManager = ApiManager;
__exportStar(require("./controller"), exports);
//# sourceMappingURL=index.js.map