@nimee/initialize-ms 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/index.js
CHANGED
|
@@ -14,6 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const fastify_1 = __importDefault(require("./fastify"));
|
|
16
16
|
const logger_1 = __importDefault(require("@nimee/logger"));
|
|
17
|
+
const error_handler_1 = require("@nimee/error-handler");
|
|
18
|
+
const health_1 = __importDefault(require("@nimee/health"));
|
|
19
|
+
const metrics_1 = require("@nimee/metrics");
|
|
17
20
|
class AppInitializer {
|
|
18
21
|
initialize(server, serverType, serviceName, entryPointsInitializer, connectionString, dbConnection, blackFeatureList, port) {
|
|
19
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -21,6 +24,7 @@ class AppInitializer {
|
|
|
21
24
|
let fastify;
|
|
22
25
|
switch (serverType) {
|
|
23
26
|
case "fastify": {
|
|
27
|
+
logger_1.default.info("Initializing Fastify now!");
|
|
24
28
|
fastify = new fastify_1.default();
|
|
25
29
|
this.server = yield fastify.initialize(serviceName);
|
|
26
30
|
break;
|
|
@@ -35,6 +39,9 @@ class AppInitializer {
|
|
|
35
39
|
if (!blackFeatureList.includes("redis")) {
|
|
36
40
|
// await redisService.initRedisConnection(this.serviceName, `${this.serviceName}_`);
|
|
37
41
|
}
|
|
42
|
+
error_handler_1.errorHandler.registerAndHandleAllErrors(this.server);
|
|
43
|
+
yield new health_1.default(this.server, undefined).start(this.serviceName);
|
|
44
|
+
metrics_1.defaultMetricsExporter.collectDefaultMetricsAndExport(this.server, "/metrics", 2000, process.env.logLevel);
|
|
38
45
|
if (entryPointsInitializer) {
|
|
39
46
|
const allEntryPointInitializers = [entryPointsInitializer];
|
|
40
47
|
allEntryPointInitializers.forEach((entryPointInitializer) => {
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wDAAiD;AACjD,2DAAmC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wDAAiD;AACjD,2DAAmC;AACnC,wDAAoD;AACpD,2DAA0C;AAC1C,4CAAwD;AACxD,MAAM,cAAc;IAKZ,UAAU,CACd,MAAW,EACX,UAAkB,EAClB,WAAmB,EACnB,sBAA2B,EAC3B,gBAAwB,EACxB,YAAiB,EACjB,gBAA+B,EAC/B,IAAY;;YAEZ,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;YAC/B,IAAI,OAAO,CAAC;YACZ,QAAQ,UAAU,EAAE;gBAClB,KAAK,SAAS,CAAC,CAAC;oBACd,gBAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;oBACzC,OAAO,GAAG,IAAI,iBAAwB,EAAE,CAAC;oBACzC,IAAI,CAAC,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;oBACpD,MAAM;iBACP;gBACD,KAAK,SAAS,CAAC,CAAC;oBACd,8EAA8E;oBAC9E,MAAM;iBACP;aACF;YACD,IAAI,YAAY,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,MAAM,YAAY,CAAC,WAAW,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;YACvH,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACvC,oFAAoF;aACrF;YACD,4BAAY,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrD,MAAM,IAAI,gBAAa,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACxE,gCAAsB,CAAC,8BAA8B,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAE3G,IAAI,sBAAsB,EAAE;gBAC1B,MAAM,yBAAyB,GAAG,CAAC,sBAAsB,CAAC,CAAC;gBAC3D,yBAAyB,CAAC,OAAO,CAAC,CAAC,qBAAqB,EAAE,EAAE;oBAC1D,gBAAM,CAAC,IAAI,CAAC,mDAAmD,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;oBACtF,IAAI,qBAAqB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACtD,CAAC,CAAC,CAAC;gBACH,gBAAM,CAAC,IAAI,CAAC,sCAAsC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;aAC1E;YACD,IAAI,UAAU;gBAAE,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;KAAA;CACF;AAED,kBAAe,cAAc,CAAC"}
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
15
|
+
const error_handler_1 = require("@nimee/error-handler");
|
|
16
16
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
17
17
|
const logger_1 = __importDefault(require("@nimee/logger"));
|
|
18
18
|
let connectionIntance;
|
|
@@ -31,13 +31,13 @@ class MongooseConnection {
|
|
|
31
31
|
return this.db;
|
|
32
32
|
}
|
|
33
33
|
yield mongoose_1.default.connect(connectionString, { autoIndex: true, autoCreate: true }).catch(function (error) {
|
|
34
|
-
|
|
34
|
+
error_handler_1.errorHandler.handleError(error);
|
|
35
35
|
});
|
|
36
36
|
logger_1.default.info(`Connected successfully to mongo server from ${serviceName}`);
|
|
37
37
|
this.db = mongoose_1.default.connection;
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new error_handler_1.CustomError(`${serviceName}_mongoose_connection_failed`, 400, `connectToDb from ${serviceName} with error ${error.message}`, error);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongooseConnection.js","sourceRoot":"","sources":["../../src/mongooseConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"mongooseConnection.js","sourceRoot":"","sources":["../../src/mongooseConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wDAAiE;AACjE,wDAAgD;AAChD,2DAAmC;AACnC,IAAI,iBAAsB,CAAC;AAE3B,MAAM,kBAAkB;IAEtB,MAAM,CAAC,kBAAkB;QACvB,IAAI,CAAC,iBAAiB,EAAE;YACtB,iBAAiB,GAAG,IAAI,kBAAkB,EAAE,CAAC;SAC9C;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACK,WAAW,CAAC,gBAAwB,EAAE,WAAmB;;YAC7D,IAAI;gBACF,IAAI,IAAI,CAAC,EAAE,EAAE;oBACX,gBAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;oBACvC,OAAO,IAAI,CAAC,EAAE,CAAC;iBAChB;gBAED,MAAM,kBAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,KAAK;oBACnG,4BAAY,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBAClC,CAAC,CAAC,CAAC;gBACH,gBAAM,CAAC,IAAI,CAAC,+CAA+C,WAAW,EAAE,CAAC,CAAC;gBAE1E,IAAI,CAAC,EAAE,GAAG,kBAAQ,CAAC,UAAU,CAAC;aAC/B;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,IAAI,2BAAW,CACnB,GAAG,WAAW,6BAA6B,EAC3C,GAAG,EACH,oBAAoB,WAAW,eAAe,KAAK,CAAC,OAAO,EAAE,EAC7D,KAAK,CACN,CAAC;aACH;QACH,CAAC;KAAA;CACF;AACD,kBAAe,kBAAkB,CAAC,kBAAkB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimee/initialize-ms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "init behavior for each ms",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"author": "dan goldberg",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@fastify/cors": "^8.1.1",
|
|
29
29
|
"@fastify/swagger": "^8.1.0",
|
|
30
|
-
"@nimee/logger": "
|
|
30
|
+
"@nimee/logger": "1.0.20",
|
|
31
|
+
"@nimee/error-handler": "0.0.1",
|
|
31
32
|
"fastify": "^4.6.0",
|
|
32
33
|
"mongoose": "6.2.10"
|
|
33
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import ServerInitializerFastify from "./fastify";
|
|
2
2
|
import logger from "@nimee/logger";
|
|
3
|
-
|
|
3
|
+
import { errorHandler } from "@nimee/error-handler";
|
|
4
|
+
import HealthService from "@nimee/health";
|
|
5
|
+
import { defaultMetricsExporter } from "@nimee/metrics";
|
|
4
6
|
class AppInitializer {
|
|
5
7
|
public httpServer: any;
|
|
6
8
|
public port: number;
|
|
@@ -20,6 +22,7 @@ class AppInitializer {
|
|
|
20
22
|
let fastify;
|
|
21
23
|
switch (serverType) {
|
|
22
24
|
case "fastify": {
|
|
25
|
+
logger.info("Initializing Fastify now!");
|
|
23
26
|
fastify = new ServerInitializerFastify();
|
|
24
27
|
this.server = await fastify.initialize(serviceName);
|
|
25
28
|
break;
|
|
@@ -33,6 +36,9 @@ class AppInitializer {
|
|
|
33
36
|
if (!blackFeatureList.includes("redis")) {
|
|
34
37
|
// await redisService.initRedisConnection(this.serviceName, `${this.serviceName}_`);
|
|
35
38
|
}
|
|
39
|
+
errorHandler.registerAndHandleAllErrors(this.server);
|
|
40
|
+
await new HealthService(this.server, undefined).start(this.serviceName);
|
|
41
|
+
defaultMetricsExporter.collectDefaultMetricsAndExport(this.server, "/metrics", 2000, process.env.logLevel);
|
|
36
42
|
|
|
37
43
|
if (entryPointsInitializer) {
|
|
38
44
|
const allEntryPointInitializers = [entryPointsInitializer];
|