diff --git a/libs/api-gateway/api-gateway.module.ts b/libs/api-gateway/api-gateway.module.ts index e3f9982..42b56bf 100644 --- a/libs/api-gateway/api-gateway.module.ts +++ b/libs/api-gateway/api-gateway.module.ts @@ -11,7 +11,7 @@ export class ApiGatewayModule { return { global: true, module: ApiGatewayModule, - imports: [ThrottlerModule.forRoot(option.throttler), RestfulModule], + imports: [ThrottlerModule.forRoot(option.throttler), RestfulModule.forRoot(option.restful)], controllers: [], providers: [ { diff --git a/libs/api-gateway/restful/restful.module.ts b/libs/api-gateway/restful/restful.module.ts index a8c5e44..f2a1cdf 100644 --- a/libs/api-gateway/restful/restful.module.ts +++ b/libs/api-gateway/restful/restful.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { DynamicModule, Module } from '@nestjs/common'; import { ProxyController } from './controllers/proxy.controller'; import { HttpModule } from '@nestjs/axios'; import { ProxyService } from './services/proxy.service'; @@ -7,10 +7,17 @@ import { RequestService } from './services/request.service'; import { DocumentController } from './controllers/document.controller'; import { UpdateApiDocumentTask } from './tasks/update-api-document.task'; import { WsRequestService } from './services/ws-request.service'; +import { RestfulOption } from './types/restful-option.type'; -@Module({ - imports: [HttpModule], - controllers: [DocumentController, ProxyController], - providers: [ProxyService, OpenApiService, RequestService, WsRequestService, UpdateApiDocumentTask] -}) -export class RestfulModule {} +@Module({}) +export class RestfulModule { + static forRoot(option: RestfulOption): DynamicModule { + console.log(option.isEnableDocument); + return { + module: RestfulModule, + imports: [HttpModule], + controllers: [...(option.isEnableDocument ? [DocumentController] : []), ProxyController], + providers: [ProxyService, OpenApiService, RequestService, WsRequestService, UpdateApiDocumentTask] + }; + } +} diff --git a/libs/api-gateway/restful/types/restful-option.type.ts b/libs/api-gateway/restful/types/restful-option.type.ts new file mode 100644 index 0000000..c3fb537 --- /dev/null +++ b/libs/api-gateway/restful/types/restful-option.type.ts @@ -0,0 +1,3 @@ +export type RestfulOption = { + isEnableDocument: boolean; +}; diff --git a/libs/api-gateway/types/api-gateway-option.type.ts b/libs/api-gateway/types/api-gateway-option.type.ts index bbb25f4..ab24d78 100644 --- a/libs/api-gateway/types/api-gateway-option.type.ts +++ b/libs/api-gateway/types/api-gateway-option.type.ts @@ -1,10 +1,12 @@ import { ThrottlerOption } from '../throttlers/types/throttler-option.type'; import { ApiServiceDetail } from '../restful/types/api-service.type'; +import { RestfulOption } from '../restful/types/restful-option.type'; export type ApiGatewayOption = { apiServices: ApiServiceDetail[]; excludeHeaders: string[]; openApiSecurityKeys: string[]; throttler: ThrottlerOption; + restful: RestfulOption; libraryPath?: string; }; diff --git a/package-lock.json b/package-lock.json index 2aaf30b..54d2aff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hodfords/nestjs-api-gateway", - "version": "10.0.11", + "version": "10.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hodfords/nestjs-api-gateway", - "version": "10.0.11", + "version": "10.1.0", "license": "UNLICENSED", "dependencies": { "@squarecloud/http-proxy": "1.2.0" diff --git a/package.json b/package.json index 6d9836f..ee051d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hodfords/nestjs-api-gateway", - "version": "10.0.11", + "version": "10.1.0", "description": "The API Gateway houses the source code and documentation for the API Gateway - a powerful and versatile solution for managing and deploying APIs within a distributed and microservices-oriented architecture.", "author": "", "private": false, diff --git a/src/app.module.ts b/src/app.module.ts index fd86af1..c1314dc 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -20,7 +20,8 @@ import { env } from '~config/env.config'; globalRateLimit: 60, isEnable: true, globalRateLimitTTL: 60 - } + }, + restful: { isEnableDocument: true } }) ], controllers: [AppController],