diff --git a/.env.demo b/.env.demo index 102d61508..92f8f7b4b 100644 --- a/.env.demo +++ b/.env.demo @@ -342,6 +342,9 @@ CONSUMER_CONFIG_MAX_DELIVER=4 AGGREGATE_STREAM=aggregate DID_STREAM=did-notify PULL_CONSUMER=hub-pull-consumer + +ENABLE_SWAGGER=true + STATUS_LIST_HOST= # Full NATS connection URL diff --git a/apps/api-gateway/src/app.controller.ts b/apps/api-gateway/src/app.controller.ts index a778b44ba..c28b7d101 100644 --- a/apps/api-gateway/src/app.controller.ts +++ b/apps/api-gateway/src/app.controller.ts @@ -1,10 +1,26 @@ -import { Controller, Logger } from '@nestjs/common'; -import { ApiBearerAuth } from '@nestjs/swagger'; +import { Controller, Get, Logger, Redirect } from '@nestjs/common'; +import { ApiBearerAuth, ApiExcludeEndpoint } from '@nestjs/swagger'; import { AppService } from './app.service'; +import { ConfigService } from '@credebl/config/config.service'; + @Controller() @ApiBearerAuth() -export class AppController { - constructor(private readonly appService: AppService) {} +export class AppController { + constructor( + private readonly appService: AppService, + private readonly configService: ConfigService + ) {} + + private readonly logger = new Logger('AppController'); + + @Get() + @Redirect('/api', 302) + @ApiExcludeEndpoint() + redirectToSwagger(): { url?: string; statusCode: number } { + if (this.configService.isSwaggerAvailable) { + return { url: '/api', statusCode: 302 }; + } - private readonly logger = new Logger('AppController'); + return { statusCode: 200 }; + } } diff --git a/libs/config/src/config.service.ts b/libs/config/src/config.service.ts index f94305b82..2d5044990 100644 --- a/libs/config/src/config.service.ts +++ b/libs/config/src/config.service.ts @@ -25,4 +25,8 @@ export class ConfigService { private get environment(): string { return this.configService.get('NODE_ENV'); } + + get isSwaggerAvailable(): boolean { + return 'true' === this.configService.get('ENABLE_SWAGGER'); + } }