-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
WebSocket Gateway - doesn't work with ExpressAdapter #2355
Comments
Try to const httpServer = await https.createServer(httpsOptions, server).listen(port);
app.useWebSocketAdapter(new IoAdapter(httpServer));
await app.init(); |
If you replace this line: http.createServer(server).listen(3000); with this line await app.listen(3000); it's gonna work fine. Why are you trying to spin up const httpServer = app.getHttpServer(); Also, you don't have to use const express = app.getHttpAdapter().getInstance(); |
EDIT: Thanks for quick answer, but sadly your answer with just replacing the initialization to |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
Current behavior
WebSocket Gateway is not working properly when Nest application is created by using ExpressAdapter.
It seems that the gateway is not linked properly to the http service - client gets 404 upon connection, gateway itself seems to be initiated (OnGatewayInit is executed with meaningful result).
Input Code
I've created minimal code to reproduce.
In the main.ts there are two bootstrap method implementations - one works, second one doesn't.
There is client.js file to simulate the client. Simply run it with node client.js - it should produce console logs in both server (when socket is properly connected) and in client (upon connection error).
https://github.com/adrianpiesiak/NestJs-socket-bug
Expected behavior
The WebSocketGateway should work in both bootstrapping methods
Environment
Node: 10.15.2
@nestjs/core@6.3.1
@nestjs/common@6.3.1
@nestjs/platform-socket.io@6.3.1
@nestjs/platform-express@6.3.1
The text was updated successfully, but these errors were encountered: