diff --git a/src/app.module.ts b/src/app.module.ts index 31d35cd..e355295 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,12 +3,14 @@ import { AutomapperModule } from '@automapper/nestjs'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ConfigurationModule } from './modules/configuration/configuration.module'; +import { HealthModule } from './modules/health/health.module'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true }), AutomapperModule.forRoot({ strategyInitializer: classes() }), ConfigurationModule, + HealthModule, ], controllers: [], providers: [], diff --git a/src/main.ts b/src/main.ts index db4f1f8..7aaf52e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,11 +9,14 @@ async function bootstrap() { { transport: Transport.GRPC, options: { - package: 'configuration', - protoPath: join( - __dirname, - 'modules/configuration/adapters/primaries/configuration.proto', - ), + package: ['configuration', 'health'], + protoPath: [ + join( + __dirname, + 'modules/configuration/adapters/primaries/configuration.proto', + ), + join(__dirname, 'modules/health/adapters/primaries/health.proto'), + ], url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT, loader: { keepCase: true }, }, diff --git a/src/modules/health/adapters/primaries/health.controller.ts b/src/modules/health/adapters/primaries/health.controller.ts new file mode 100644 index 0000000..843a4a9 --- /dev/null +++ b/src/modules/health/adapters/primaries/health.controller.ts @@ -0,0 +1,27 @@ +import { Controller } from '@nestjs/common'; +import { GrpcMethod } from '@nestjs/microservices'; + +enum ServingStatus { + UNKNOWN = 0, + SERVING = 1, + NOT_SERVING = 2, +} + +interface HealthCheckRequest { + service: string; +} + +interface HealthCheckResponse { + status: ServingStatus; +} + +@Controller() +export class HealthController { + @GrpcMethod('Health', 'Check') + // eslint-disable-next-line @typescript-eslint/no-unused-vars + check(data: HealthCheckRequest, metadata: any): HealthCheckResponse { + return { + status: ServingStatus.SERVING, + }; + } +} 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 {}