From c0888fb5e69420fa66b3452a48ba24c1aade4476 Mon Sep 17 00:00:00 2001 From: tanghel Date: Thu, 8 Aug 2024 15:28:43 +0300 Subject: [PATCH] make websocket microservice configurable --- config/config.devnet.yaml | 1 + config/config.mainnet.yaml | 1 + config/config.testnet.yaml | 1 + src/common/api-config/api.config.service.ts | 4 +++ src/main.ts | 32 +++++++++++---------- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/config/config.devnet.yaml b/config/config.devnet.yaml index a4f21b2f5..7d61c66ef 100644 --- a/config/config.devnet.yaml +++ b/config/config.devnet.yaml @@ -5,6 +5,7 @@ api: publicPort: 3001 private: true privatePort: 4001 + websocket: true cron: cacheWarmer: true fastWarm: true diff --git a/config/config.mainnet.yaml b/config/config.mainnet.yaml index 914acccc1..da3b0645b 100644 --- a/config/config.mainnet.yaml +++ b/config/config.mainnet.yaml @@ -5,6 +5,7 @@ api: publicPort: 3001 private: true privatePort: 4001 + websocket: true cron: cacheWarmer: true fastWarm: false diff --git a/config/config.testnet.yaml b/config/config.testnet.yaml index 0b55ee343..b4cc3485c 100644 --- a/config/config.testnet.yaml +++ b/config/config.testnet.yaml @@ -5,6 +5,7 @@ api: publicPort: 3001 private: true privatePort: 4001 + websocket: true cron: cacheWarmer: true fastWarm: true diff --git a/src/common/api-config/api.config.service.ts b/src/common/api-config/api.config.service.ts index 8e9005256..d806f15c7 100644 --- a/src/common/api-config/api.config.service.ts +++ b/src/common/api-config/api.config.service.ts @@ -397,6 +397,10 @@ export class ApiConfigService { return isApiActive; } + getIsWebsocketApiActive(): boolean { + return this.configService.get('api.websocket') ?? true; + } + getPrivateApiPort(): number { return this.configService.get('api.privatePort') ?? 4001; } diff --git a/src/main.ts b/src/main.ts index 473a7e41b..72f8d64b1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -59,22 +59,24 @@ async function bootstrap() { await publicApp.listen(apiConfigService.getPublicApiPort()); - const websocketPublisherApp = await NestFactory.createMicroservice( - WebSocketPublisherModule, - { - transport: Transport.REDIS, - options: { - host: apiConfigService.getRedisUrl(), - port: 6379, - retryAttempts: 100, - retryDelay: 1000, - retryStrategy: () => 1000, + if (apiConfigService.getIsWebsocketApiActive()) { + const websocketPublisherApp = await NestFactory.createMicroservice( + WebSocketPublisherModule, + { + transport: Transport.REDIS, + options: { + host: apiConfigService.getRedisUrl(), + port: 6379, + retryAttempts: 100, + retryDelay: 1000, + retryStrategy: () => 1000, + }, }, - }, - ); - websocketPublisherApp.useWebSocketAdapter(new SocketAdapter(websocketPublisherApp)); - // eslint-disable-next-line @typescript-eslint/no-floating-promises - websocketPublisherApp.listen(); + ); + websocketPublisherApp.useWebSocketAdapter(new SocketAdapter(websocketPublisherApp)); + // eslint-disable-next-line @typescript-eslint/no-floating-promises + websocketPublisherApp.listen(); + } } if (apiConfigService.getIsPrivateApiActive()) {