whats the url of deployed socket.io server

i have a nodejs socket.io server idk the url to my websocket server in nodejs I do const io = new Server(1001, { cors: { origin: ["https://deployedclient.vercel.app", "http://localhost:3000"] } }) and client knows that the websocket is hosted on localhost:1001 but in deployed server, the domain of the server would be something like deployedserver.com but client cant connect to deployedserver.com:1001
5 Replies
JulieCezar
JulieCezar2y ago
You can't do websockets on Vercel. The backend there is made of Lambdas. Meaning a new Server is spun up when you make an api request, and more are started when traffic gets too hig After it's done doing it's job it closes Meaning it cannot be stateful, and sockets are stateful... For that you need to deploy somewhere else or use some service, like Pusher - socket SAAS
JulieCezar
JulieCezar2y ago
JulieCezar
JulieCezar2y ago
Theo has a video where he uses pusher in one of his apps but idk which one it was
hyhy
hyhy2y ago
GitHub
GitHub - pingdotgg/zapdos
Contribute to pingdotgg/zapdos development by creating an account on GitHub.
Samyar
Samyar2y ago
The answer is fairly simple if your socket is deployed on deployedserver.com then you should not use a port at the end and just use the url but if it's running on another port except 80 witch this url refers to in the server you should use nginx to create another server block to host your socket application if you want to deploy your socket in a url create a new subdomain, for example in my case i did : socket.example.com and then i created a new nginx config in my server to reverse proxy to the localhost:4000 (my socket app is running in this port) this article might be helpful : https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-on-ubuntu-22-04
How To Configure Nginx as a Reverse Proxy on Ubuntu 22.04 | Digita...
This tutorial will demonstrate how to set up a reverse proxy using Nginx, a popular web server and reverse proxy solution. You will install Nginx, configure …
Want results from more Discord servers?
Add your server