According to the NestJS docs I've implemented the websockets gateway and providing it inside of the AppModule. The server is starting properly and I can serve static assets via http successfully. But I can't get the websockets running at all, the ws server is not available at ws://localhost:3333 and the afterInit function is not executed at all. Even not when I am defining the @SubscribeMessage.
The gateway is implemented as
@WebSocketGateway()
export class SocketGateway implements OnGatewayInit {
afterInit() {
console.log('Gateway initialized');
}
}
The AppModule provides the gateway properly
@Module({
providers: [SocketGateway]
})
export class AppModule {}
And this is the bootstrap implementation
export async function bootstrap() {
let app = await NestFactory.create(AppModule);
await app.listen(process.env.port || 3333, () => {
console.log(`Listening at http://localhost:${port}`);
});
}
bootstrap();
My dependecies are
"socket.io-client": "^2.2.0",
"@nestjs/common": "5.5.0",
"@nestjs/core": "5.5.0",
"@nestjs/platform-socket.io": "^6.1.0",
"@nestjs/websockets": "^6.1.0"
Maybe you see the problem directly. Thanks for your help, cheers!