diff --git a/apps/credential-manager/package.json b/apps/credential-manager/package.json index 35e5df570b68ff70a1cba9c3760524baf5f4bac9..b0c8f8635442332267d277d2cddb96e07a9ed98c 100644 --- a/apps/credential-manager/package.json +++ b/apps/credential-manager/package.json @@ -24,15 +24,13 @@ "test:e2e": "jest --config ./test/jest.config.js" }, "dependencies": { - "@nestjs/axios": "^3.0.1", "@nestjs/common": "^10.2.10", "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.2.10", "@nestjs/microservices": "^10.2.10", "@nestjs/platform-express": "^10.2.8", "@nestjs/swagger": "^7.1.16", - "@nestjs/terminus": "^10.1.1", - "axios": "^1.6.2", + "@ocm/shared": "workspace:*", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "express": "^4.17.3", diff --git a/apps/credential-manager/src/__tests__/application.spec.ts b/apps/credential-manager/src/__tests__/application.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..3973b1ea42fa35c5bfcee55e345334d4c7d414e3 --- /dev/null +++ b/apps/credential-manager/src/__tests__/application.spec.ts @@ -0,0 +1,26 @@ +import type { INestApplication } from '@nestjs/common'; + +import { Test } from '@nestjs/testing'; + +import { Application } from '../application.js'; + +describe('Application', () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleFixture = await Test.createTestingModule({ + imports: [Application], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + afterAll(async () => { + await app.close(); + }); + + it('should be defined', () => { + expect(app).toBeDefined(); + }); +}); diff --git a/apps/credential-manager/src/app.module.ts b/apps/credential-manager/src/app.module.ts deleted file mode 100644 index 2f9297aa61f499f40dae0322601671a7e44b8039..0000000000000000000000000000000000000000 --- a/apps/credential-manager/src/app.module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Module } from '@nestjs/common'; -import { ConfigModule } from '@nestjs/config'; - -import { httpConfig } from './config/http.config.js'; -import { natsConfig } from './config/nats.config.js'; -import { ssiConfig } from './config/ssi.config.js'; -import { validationSchema } from './config/validation.js'; -import { HealthModule } from './health/health.module.js'; - -@Module({ - imports: [ - ConfigModule.forRoot({ - isGlobal: true, - load: [httpConfig, natsConfig, ssiConfig], - cache: true, - expandVariables: true, - validationSchema, - validationOptions: { - allowUnknown: true, - abortEarly: true, - }, - }), - HealthModule, - ], -}) -export default class AppModule {} diff --git a/apps/credential-manager/src/application.ts b/apps/credential-manager/src/application.ts new file mode 100644 index 0000000000000000000000000000000000000000..fb1bd0ec1b2bcb2625aeebddd01820807c7c12ab --- /dev/null +++ b/apps/credential-manager/src/application.ts @@ -0,0 +1,45 @@ +import type { ConfigType } from '@nestjs/config'; + +import { Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import { RouterModule } from '@nestjs/core'; +import { HealthModule } from '@ocm/shared'; + +import { httpConfig } from './config/http.config.js'; +import { natsConfig } from './config/nats.config.js'; +import { ssiConfig } from './config/ssi.config.js'; +import { validationSchema } from './config/validation.js'; + +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + load: [httpConfig, natsConfig, ssiConfig], + cache: true, + expandVariables: true, + validationSchema, + validationOptions: { + allowUnknown: true, + abortEarly: true, + }, + }), + + HealthModule.registerAsync({ + inject: [natsConfig.KEY], + useFactory: (config: ConfigType<typeof natsConfig>) => { + const options: Parameters<typeof HealthModule.register>[0] = {}; + + if (config.monitoringUrl) { + options.nats = { + monitoringUrl: config.monitoringUrl as string, + }; + } + + return options; + }, + }), + + RouterModule.register([{ module: HealthModule, path: '/health' }]), + ], +}) +export class Application {} diff --git a/apps/credential-manager/src/health/health.controller.ts b/apps/credential-manager/src/health/health.controller.ts deleted file mode 100644 index 9f2454eb869df9f7720c6e7bd1caa2ed4caef8d6..0000000000000000000000000000000000000000 --- a/apps/credential-manager/src/health/health.controller.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { HealthIndicatorFunction } from '@nestjs/terminus'; - -import { Controller, Get } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import { - HealthCheck, - HealthCheckService, - HttpHealthIndicator, -} from '@nestjs/terminus'; - -@Controller('health') -export class HealthController { - public constructor( - private readonly config: ConfigService, - private readonly health: HealthCheckService, - private readonly http: HttpHealthIndicator, - ) {} - - @Get() - @HealthCheck() - public check() { - const healthIndicators: HealthIndicatorFunction[] = []; - - const natsMonitoringUrl = this.config.get('nats.monitoringUrl'); - if (typeof natsMonitoringUrl === 'string') { - healthIndicators.push(() => - this.http.pingCheck('nats', natsMonitoringUrl), - ); - } else { - healthIndicators.push(() => ({ nats: { status: 'down' } })); - } - - return this.health.check(healthIndicators); - } -} diff --git a/apps/credential-manager/src/health/health.module.ts b/apps/credential-manager/src/health/health.module.ts deleted file mode 100644 index 17ccd14e59cbfcc2c577204b278363bf15be4e7b..0000000000000000000000000000000000000000 --- a/apps/credential-manager/src/health/health.module.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { ConfigType } from '@nestjs/config'; - -import { HttpModule } from '@nestjs/axios'; -import { Module } from '@nestjs/common'; -import { ClientsModule, Transport } from '@nestjs/microservices'; -import { TerminusModule } from '@nestjs/terminus'; - -import { SERVICE_NAME } from '../common/constants.js'; -import { natsConfig } from '../config/nats.config.js'; - -import { HealthController } from './health.controller.js'; - -@Module({ - imports: [ - TerminusModule, - HttpModule, - ClientsModule.registerAsync({ - clients: [ - { - name: SERVICE_NAME, - inject: [natsConfig.KEY], - useFactory: (config: ConfigType<typeof natsConfig>) => ({ - transport: Transport.NATS, - options: { - servers: [config.url as string], - }, - }), - }, - ], - }), - ], - controllers: [HealthController], -}) -export class HealthModule {} diff --git a/apps/credential-manager/src/main.ts b/apps/credential-manager/src/main.ts index 4936407a8a19d52a4391a73f5f12faf6f76b04d8..2b5dccd2368d7a458d0d28c168eefc37962b66b2 100644 --- a/apps/credential-manager/src/main.ts +++ b/apps/credential-manager/src/main.ts @@ -6,9 +6,9 @@ import { NestFactory } from '@nestjs/core'; import { Transport } from '@nestjs/microservices'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; -import AppModule from './app.module.js'; +import { Application } from './application.js'; -const app = await NestFactory.create(AppModule); +const app = await NestFactory.create(Application); const configService = app.get(ConfigService); app.enableCors();