Closed J-Hoh closed 2 years ago
Made an update to my reproduction repo as im trying to investigate this error. This bug still persists in the latest version, 9.0.5
However, I discovered that setting a different port than the main fastify server, makes the socket.io connection work. Furthermore, I can confirm that setting the port to the same (fastify/NestJS server AND the socket.io gateway) means any ws:// protocol will still get handled by the fastify server. (unwanted)
Hey @J-Hoh,
I am also experiencing this issue, however I found that this is only the case in my local dev environment and not when I have deployed to production, can you confirm if you are experiencing the same?
Just tried it in my reproduction repo above,
running npm run build
and npm run start:prod
(essentially nest build
and then running the resulting main.js via node).
For some reason this does not resolve the issue here... Still, using a different port (thus creating a new underlying http server?) does work and is my current workaround
I have the same problem, is there a solution now?
My workaround stopped working in production and I've reverted back to using express for the time being
On Sun, 31 Jul 2022, 06:52 bqy_fe, @.***> wrote:
I have the same problem, is there a solution now?
ā Reply to this email directly, view it on GitHub https://github.com/nestjs/nest/issues/9903#issuecomment-1200348130, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM67VIUJIRYDUU6EC3226L3VWYBBXANCNFSM53FLFB2Q . You are receiving this because you commented.Message ID: @.***>
have the same issue both for socket.io
and ws
@J-Hoh I was able to launch my app after downgrading @nestjs/platform-fastify
to 8.4.7
. I can't confirm that everything works fine but at least I've got connected to WS.
P.S. using downgraded package you should also add as any
right after new FastifyAdapter()
in your main.ts
file if you're using TypeScript
I had a similar problem. After specifying the host (e.g. await app.listen(3000,'127.0.0.1')
) according to https://github.com/fastify/fastify/issues/4053, socket.io started working again. I'm using latest version of NestJs and Fastify.
@KaMeHb-UA @urdeveloper I'm pretty sure the problem was introduced with the upgrade to 9.0.0 of NestJS packages, and the problem is with having a websocket server on the same host+port as the actual fastify http server.
Using a different port or even just specifying a host will create a separate server. Using the same port or not specifying a host means the http fastify server will be used to register the websocket server, which seems to not work after 9.0.0? The issue isnt big enough for me to try and investigate further, and the workaround of using a separate port is fairly simple.
I can't reproduce this issue with the latest versions of deps
I had a similar problem. After specifying the host (e.g.
await app.listen(3000,'127.0.0.1')
) according to fastify/fastify#4053, socket.io started working again. I'm using latest version of NestJs and Fastify.
I just had a similar issue with Mercurius websockets not working at all in certain cases, and this comment helped fix it.
any update on this, it seems like i can't connect to socket with my client ( mobile app ) with nestJs version 9.*
Is there an existing issue for this?
Current behavior
Using NestJS@9 with the fastify-adapter and socket.io, WebsocketGateways initiate and everything else serverside seems to work, but I cannot get any clients to connect anymore. This problem did not exist on NestJS@8
On a bigger repo i get a 404 error for every trying socket.io client connection:
From the error i gather that the request gets passed through the fastify instance, getting checked by its cors module (for which I've tried and set origin to "*") but it seems to be searching for an http get route, instead of the websocket upgrade way.
The minimum reproduction code below has 4 branches, NestJS@8/9 paired with fastify@3/4 respectively, and express@4. The issue is not present when using express. The issue is also not present with NestJS@8 and thus fastify@3.
It does not seem to me like this issue is coming from fastify@4, as this repos example uses fastify@4 without a problem.
Minimum reproduction code
https://github.com/J-Hoh/nestjs9_fastify4_socketio-bug/tree/nest9_express4
Steps to reproduce
No response
Expected behavior
Client websockets to connect / The server instance handling the upgrade request properly
Package
Other package
No response
NestJS version
9.0.1
Packages versions
Node.js version
16.15.1
In which operating systems have you tested?
Other
No response