inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
81 lines • 3.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestInceptumApp = exports.InceptumApp = exports.DEFAULT_INCEPTUM_APP_OPTIONS = void 0;
const ElasticsearchPlugin_1 = require("../elasticsearch/ElasticsearchPlugin");
const HealthCheckPlugin_1 = require("../health/HealthCheckPlugin");
const AdminPortPlugin_1 = require("../web/AdminPortPlugin");
const MySQLPlugin_1 = require("../mysql/MySQLPlugin");
const PostgresPlugin_1 = require("../postgres/PostgresPlugin");
const RabbitmqClientPlugin_1 = require("../rabbitmq/RabbitmqClientPlugin");
const NewrelicPlugin_1 = require("../newrelic/NewrelicPlugin");
const SqsClientPlugin_1 = require("../sqs/SqsClientPlugin");
const SqsWorkerPlugin_1 = require("../sqs/SqsWorkerPlugin");
const MetricsPlugin_1 = require("../metrics/MetricsPlugin");
const BaseApp_1 = require("./BaseApp");
const AutowirePlugin_1 = require("./plugin/AutowirePlugin");
const DecoratorPlugin_1 = require("./plugin/DecoratorPlugin");
const LazyLoadingPlugin_1 = require("./plugin/LazyLoadingPlugin");
const StartStopPlugin_1 = require("./plugin/StartStopPlugin");
exports.DEFAULT_INCEPTUM_APP_OPTIONS = {
enableAdminPort: true,
enableHealthChecks: true,
enableMetrics: true,
shutdownTimer: process.env.NODE_ENV === 'production' ? 20000 : 200,
};
class InceptumApp extends BaseApp_1.default {
/**
* Creates a new Inceptum App
*/
constructor(options = exports.DEFAULT_INCEPTUM_APP_OPTIONS) {
super(options);
// Standard IOC plugins.
this.register(new AutowirePlugin_1.default(), new LazyLoadingPlugin_1.default(), new StartStopPlugin_1.default(), new DecoratorPlugin_1.default());
if (options.enableAdminPort) {
this.register(new AdminPortPlugin_1.default());
}
if (options.enableHealthChecks) {
this.register(new HealthCheckPlugin_1.default());
}
if (options.enableMetrics) {
this.register(new MetricsPlugin_1.default());
}
this.register(new NewrelicPlugin_1.default());
// TODO This is for backward compat, I'd like to remove it and be explicit
if (this.hasConfig('mysql')) {
this.logger.debug('Mysql Detected - Adding Plugin');
this.register(new MySQLPlugin_1.default());
}
if (this.hasConfig('postgres')) {
this.logger.debug('Postgres Detected - Adding Plugin');
this.register(new PostgresPlugin_1.default());
}
if (this.hasConfig('SqsClient')) {
this.logger.debug('SqsClient Detected - Adding Plugin');
this.register(new SqsClientPlugin_1.default());
}
if (this.hasConfig('SqsWorker')) {
this.logger.debug('SqsWorker Detected - Adding Plugin');
this.register(new SqsWorkerPlugin_1.default());
}
if (this.hasConfig('elasticsearch')) {
this.logger.debug('elasticsearch Detected - Adding Plugin');
this.register(new ElasticsearchPlugin_1.default());
}
if (this.hasConfig('rabbitmq.client')) {
this.logger.debug('rabbitmq Detected - Adding Plugin');
this.register(new RabbitmqClientPlugin_1.default());
}
}
}
exports.InceptumApp = InceptumApp;
class TestInceptumApp extends InceptumApp {
constructor(ops = {}) {
super(Object.assign({ enableAdminPort: false, enableHealthChecks: false, enableMetrics: false }, ops));
}
async start() {
process.removeAllListeners();
await super.start();
}
}
exports.TestInceptumApp = TestInceptumApp;
//# sourceMappingURL=InceptumApp.js.map