Socket io not working on vercel (Update: socket.io is now supported in Vercel) #4628
-
It works fine in localhost but not working in hosting
// page/api/socket
// Client side
//updated |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi! Is there any error in the console? You can also check our troubleshooting guide: https://socket.io/docs/v4/troubleshooting-connection-issues/ |
Beta Was this translation helpful? Give feedback.
-
const io = new Server(res.socket.server,{ path: '/api/socket',addTrailingSlash: false }); by addTrailingSlash: false |
Beta Was this translation helpful? Give feedback.
-
For future readers: Socket.IO can indeed be used in conjunction with Next.js: https://socket.io/how-to/use-with-nextjs However, a Socket.IO application cannot be deployed on Vercel, as it is not suitable for long-running connections, like HTTP long-polling or WebSockets: https://vercel.com/guides/do-vercel-serverless-functions-support-websocket-connections |
Beta Was this translation helpful? Give feedback.
const io = new Server(res.socket.server,{ path: '/api/socket',addTrailingSlash: false });
res.socket.server.io = io;
by addTrailingSlash: false
socket.io in now working in vercel