Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable websocket API #1303

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ api:
publicPort: 3001
private: true
privatePort: 4001
websocket: true
cron:
cacheWarmer: true
fastWarm: true
Expand Down
1 change: 1 addition & 0 deletions config/config.mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ api:
publicPort: 3001
private: true
privatePort: 4001
websocket: true
cron:
cacheWarmer: true
fastWarm: false
Expand Down
1 change: 1 addition & 0 deletions config/config.testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ api:
publicPort: 3001
private: true
privatePort: 4001
websocket: true
cron:
cacheWarmer: true
fastWarm: true
Expand Down
4 changes: 4 additions & 0 deletions src/common/api-config/api.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ export class ApiConfigService {
return isApiActive;
}

getIsWebsocketApiActive(): boolean {
return this.configService.get<boolean>('api.websocket') ?? true;
}

getPrivateApiPort(): number {
return this.configService.get<number>('api.privatePort') ?? 4001;
}
Expand Down
32 changes: 17 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,24 @@ async function bootstrap() {

await publicApp.listen(apiConfigService.getPublicApiPort());

const websocketPublisherApp = await NestFactory.createMicroservice<MicroserviceOptions>(
WebSocketPublisherModule,
{
transport: Transport.REDIS,
options: {
host: apiConfigService.getRedisUrl(),
port: 6379,
retryAttempts: 100,
retryDelay: 1000,
retryStrategy: () => 1000,
if (apiConfigService.getIsWebsocketApiActive()) {
const websocketPublisherApp = await NestFactory.createMicroservice<MicroserviceOptions>(
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()) {
Expand Down
Loading