OpraSocketioModule
NestJS dynamic module that wires OPRA's Socket.IO adapter into a NestJS application.
import { OpraSocketioModule } from '@opra/nestjs-socketio';
forRoot(options)
Synchronous registration:
import { Module } from '@nestjs/common';
import { OpraSocketioModule } from '@opra/nestjs-socketio';
import { NotificationsController } from './controllers/notifications.controller.js';
@Module({
imports: [
OpraSocketioModule.forRoot({
name: 'NotificationsApi',
port: 3001,
controllers: [NotificationsController],
}),
],
})
export class AppModule {}
Options (OpraSocketioModule.ModuleOptions)
| Option | Type | Description |
|---|---|---|
name | string | API name. |
description | string | Optional API description. |
scope | string | Validation scope. |
port | number | Port the Socket.IO server listens on. |
serverOptions | Partial<socketio.ServerOptions> | Socket.IO server options (CORS, path, transports…). |
types | Type[] | Data types to register on the ApiDocument. |
references | object | Type references. |
info | object | API info metadata. |
controllers | Type[] | OPRA WebSocket controller classes. |
providers | Provider[] | Additional NestJS providers. |
exports | any[] | Providers to export. |
imports | any[] | Modules to import. |
global | boolean | Register globally. |
token | any | Custom injection token. |
interceptors | (InterceptorFunction | IWSInterceptor | Type<IWSInterceptor>)[] | Request interceptors. |
logger | Logger | Custom logger. |
forRootAsync(options)
Asynchronous registration:
OpraSocketioModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
name: 'NotificationsApi',
port: config.get<number>('WS_PORT'),
serverOptions: { cors: { origin: config.get('ALLOWED_ORIGINS') } },
controllers: [NotificationsController],
}),
})
Options (OpraSocketioModule.AsyncModuleOptions)
| Option | Type | Description |
|---|---|---|
inject | any[] | Providers to inject into useFactory. |
useFactory | (...args) => ApiConfig | Promise<ApiConfig> | Factory returning the API configuration. |
Plus all non-API fields from ModuleOptions.