From 6a0b33f7424b1889e5d0bc88140afcb5edae481f Mon Sep 17 00:00:00 2001 From: sbriat Date: Fri, 31 Mar 2023 10:09:51 +0200 Subject: [PATCH] extract health to module --- src/app.module.ts | 2 ++ src/main.ts | 3 ++- .../adapters/primaries/authentication.proto | 17 --------------- .../authentication/authentication.module.ts | 7 +------ .../adapters/primaries/health.controller.ts | 0 .../health/adapters/primaries/health.proto | 21 +++++++++++++++++++ src/modules/health/health.module.ts | 7 +++++++ 7 files changed, 33 insertions(+), 24 deletions(-) rename src/modules/{authentication => health}/adapters/primaries/health.controller.ts (100%) create mode 100644 src/modules/health/adapters/primaries/health.proto create mode 100644 src/modules/health/health.module.ts diff --git a/src/app.module.ts b/src/app.module.ts index 8afd292..e7a7114 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,6 +4,7 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { AuthenticationModule } from './modules/authentication/authentication.module'; import { AuthorizationModule } from './modules/authorization/authorization.module'; +import { HealthModule } from './modules/health/health.module'; @Module({ imports: [ @@ -11,6 +12,7 @@ import { AuthorizationModule } from './modules/authorization/authorization.modul AutomapperModule.forRoot({ strategyInitializer: classes() }), AuthenticationModule, AuthorizationModule, + HealthModule, ], controllers: [], providers: [], diff --git a/src/main.ts b/src/main.ts index 88dd40c..a1061e0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function bootstrap() { { transport: Transport.GRPC, options: { - package: ['authentication', 'authorization'], + package: ['authentication', 'authorization', 'health'], protoPath: [ join( __dirname, @@ -19,6 +19,7 @@ async function bootstrap() { __dirname, 'modules/authorization/adapters/primaries/authorization.proto', ), + join(__dirname, 'modules/health/adapters/primaries/health.proto'), ], url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT, loader: { keepCase: true, enums: String }, diff --git a/src/modules/authentication/adapters/primaries/authentication.proto b/src/modules/authentication/adapters/primaries/authentication.proto index 472ff2a..9b16d3a 100644 --- a/src/modules/authentication/adapters/primaries/authentication.proto +++ b/src/modules/authentication/adapters/primaries/authentication.proto @@ -40,20 +40,3 @@ message Uuid { } message Empty {} - -service Health { - rpc Check(HealthCheckRequest) returns (HealthCheckResponse); -} - -message HealthCheckRequest { - string service = 1; -} - -message HealthCheckResponse { - enum ServingStatus { - UNKNOWN = 0; - SERVING = 1; - NOT_SERVING = 2; - } - ServingStatus status = 1; -} diff --git a/src/modules/authentication/authentication.module.ts b/src/modules/authentication/authentication.module.ts index 3379e27..3b7ed79 100644 --- a/src/modules/authentication/authentication.module.ts +++ b/src/modules/authentication/authentication.module.ts @@ -16,7 +16,6 @@ import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { AuthenticationMessagerController } from './adapters/primaries/authentication-messager.controller'; import { Messager } from './adapters/secondaries/messager'; -import { HealthController } from './adapters/primaries/health.controller'; @Module({ imports: [ @@ -48,11 +47,7 @@ import { HealthController } from './adapters/primaries/health.controller'; inject: [ConfigService], }), ], - controllers: [ - AuthenticationController, - AuthenticationMessagerController, - HealthController, - ], + controllers: [AuthenticationController, AuthenticationMessagerController], providers: [ AuthenticationProfile, UsernameProfile, diff --git a/src/modules/authentication/adapters/primaries/health.controller.ts b/src/modules/health/adapters/primaries/health.controller.ts similarity index 100% rename from src/modules/authentication/adapters/primaries/health.controller.ts rename to src/modules/health/adapters/primaries/health.controller.ts diff --git a/src/modules/health/adapters/primaries/health.proto b/src/modules/health/adapters/primaries/health.proto new file mode 100644 index 0000000..74e1a4c --- /dev/null +++ b/src/modules/health/adapters/primaries/health.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package health; + + +service Health { + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); +} + +message HealthCheckRequest { + string service = 1; +} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + } + ServingStatus status = 1; +} diff --git a/src/modules/health/health.module.ts b/src/modules/health/health.module.ts new file mode 100644 index 0000000..1f715d5 --- /dev/null +++ b/src/modules/health/health.module.ts @@ -0,0 +1,7 @@ +import { Module } from '@nestjs/common'; +import { HealthController } from './adapters/primaries/health.controller'; + +@Module({ + controllers: [HealthController], +}) +export class HealthModule {}