@koalarx/nest 1.10.1 → 1.11.0

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.
@@ -0,0 +1,5 @@
1
+ export declare class HealthCheckController {
2
+ healthCheck(): {
3
+ status: string;
4
+ };
5
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HealthCheckController = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ let HealthCheckController = exports.HealthCheckController = class HealthCheckController {
15
+ healthCheck() {
16
+ return { status: 'ok' };
17
+ }
18
+ };
19
+ __decorate([
20
+ (0, common_1.Get)(),
21
+ __metadata("design:type", Function),
22
+ __metadata("design:paramtypes", []),
23
+ __metadata("design:returntype", void 0)
24
+ ], HealthCheckController.prototype, "healthCheck", null);
25
+ exports.HealthCheckController = HealthCheckController = __decorate([
26
+ (0, common_1.Controller)('health')
27
+ ], HealthCheckController);
@@ -0,0 +1,2 @@
1
+ export declare class HealthCheckModule {
2
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HealthCheckModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const health_check_controller_1 = require("./health-check.controller");
12
+ let HealthCheckModule = exports.HealthCheckModule = class HealthCheckModule {
13
+ };
14
+ exports.HealthCheckModule = HealthCheckModule = __decorate([
15
+ (0, common_1.Module)({
16
+ controllers: [health_check_controller_1.HealthCheckController],
17
+ })
18
+ ], HealthCheckModule);
package/core/koala-app.js CHANGED
@@ -234,6 +234,7 @@ class KoalaApp {
234
234
  if (this._apiReferenceEndpoint) {
235
235
  consola.info('API Reference:', `http://localhost:${port}${this._apiReferenceEndpoint}`);
236
236
  }
237
+ consola.info('Health Check:', `http://localhost:${port}/health`);
237
238
  consola.info('Internal Host:', `http://localhost:${port}`);
238
239
  if (this._ngrokUrl) {
239
240
  consola.info('External Host:', this._ngrokUrl);
@@ -7,6 +7,7 @@ interface KoalaNestModuleConfig {
7
7
  logging?: Provider<ILoggingService>;
8
8
  env?: ZodType;
9
9
  controllers?: Type<any>[];
10
+ healthCheck?: Type<any>;
10
11
  cronJobs?: Type<CronJobHandlerBase>[];
11
12
  eventJobs?: Type<EventHandlerBase<any>>[];
12
13
  }
@@ -19,9 +19,11 @@ const iredis_service_1 = require("../services/redis/iredis.service");
19
19
  const redis_service_1 = require("../services/redis/redis.service");
20
20
  const ired_lock_service_1 = require("../services/redlock/ired-lock.service");
21
21
  const red_lock_service_1 = require("../services/redlock/red-lock.service");
22
+ const health_check_module_1 = require("./health-check/health-check.module");
22
23
  let KoalaNestModule = exports.KoalaNestModule = KoalaNestModule_1 = class KoalaNestModule {
23
24
  static register(config) {
24
25
  const controllers = config?.controllers ?? [];
26
+ const healthCheck = config?.healthCheck ?? health_check_module_1.HealthCheckModule;
25
27
  const cronJobsProviders = config?.cronJobs ?? [];
26
28
  const eventJobsProviders = config?.eventJobs ?? [];
27
29
  const loggingServiceClass = config?.logging ?? logging_service_1.LoggingService;
@@ -33,6 +35,7 @@ let KoalaNestModule = exports.KoalaNestModule = KoalaNestModule_1 = class KoalaN
33
35
  isGlobal: true,
34
36
  }),
35
37
  env_module_1.EnvModule,
38
+ healthCheck,
36
39
  ...controllers,
37
40
  ],
38
41
  providers: [
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GlobalExceptionsFilter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const core_1 = require("@nestjs/core");
15
+ const node_http_1 = require("node:http");
15
16
  const koala_global_vars_1 = require("../core/koala-global-vars");
16
17
  const env_config_1 = require("../core/utils/env.config");
17
18
  const filter_request_params_1 = require("../core/utils/filter-request-params");
@@ -26,6 +27,7 @@ let GlobalExceptionsFilter = exports.GlobalExceptionsFilter = class GlobalExcept
26
27
  }
27
28
  catch(exception, host) {
28
29
  const filterRequestParams = filter_request_params_1.FilterRequestParams.get(host);
30
+ const request = host.getArgs().find((arg) => arg instanceof node_http_1.IncomingMessage) ?? null;
29
31
  const statusCode = exception instanceof common_1.HttpException
30
32
  ? exception.getStatus()
31
33
  : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
@@ -39,6 +41,7 @@ let GlobalExceptionsFilter = exports.GlobalExceptionsFilter = class GlobalExcept
39
41
  this.httpAdapter.reply(filterRequestParams.response, responseBody, statusCode);
40
42
  if (!exception.message?.includes('Cannot GET /socket.io') &&
41
43
  !exception.message?.includes('Cannot GET /favicon.ico') &&
44
+ !['/'].includes(request?.url ?? '') &&
42
45
  statusCode !== common_1.HttpStatus.UNAUTHORIZED) {
43
46
  if (!env_config_1.EnvConfig.isEnvTest) {
44
47
  this.loggingService
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "1.10.1",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",