I'm working with socket.io in React JS (client) and Node JS (server), and when i deployed the apps i got WebSocket connection to 'wss://***.com:57284/ws' failed.
Running locally it dont happend and i'd like to know why and how to solve it.
This is the server code
const {Server} = require("socket.io");
const port = process.env.PORT || 5000
// io.listen(port);
console.log("Server listening on " + port)
const io = new Server(port, {
cors: {
origin: "https://***.com",
methods: ["GET", "POST"]
},
path: "/api/",
});
io.on("connection", (socket) => {
***all socket logic***
});
and the client
const [socket, setSocket] = useState(null)
useEffect(() => {
const newSocket = io("https://***.com", {transports: ['websocket'], path: "/api/"})
setSocket(newSocket)
return () => newSocket.close()
}, [setSocket])