Websocket failed to connect
Unanswered
Chausie posted this in #help-forum
ChausieOP
My WebSocket client fails to connect to the WebSocket server, but when I test the connection using websocat, it works fine.
I suspect the issue might be related to TLS or Nginx not properly proxying the WebSocket connection
I suspect the issue might be related to TLS or Nginx not properly proxying the WebSocket connection
useEffect(() => {
const ws = new WebSocket(
`${process.env.NEXT_PUBLIC_WEBSOCKET}/${id}`
);
ws.onopen = () => {
console.log(`Connected with ${id}`);
};
setSocket(ws);
return () => {
ws.close();
}
}, [])2 Replies
@Chausie My WebSocket client fails to connect to the WebSocket server, but when I test the connection using websocat, it works fine.
I suspect the issue might be related to TLS or Nginx not properly proxying the WebSocket connection
javascript
useEffect(() => {
const ws = new WebSocket(
`${process.env.NEXT_PUBLIC_WEBSOCKET}/${id}`
);
ws.onopen = () => {
console.log(`Connected with ${id}`);
};
setSocket(ws);
return () => {
ws.close();
}
}, [])
Vespid wasp
If the issue is TLS. Then with:
if still can't connect, maybe problem is in your api
In your .env file
NODE_TLS_REJECT_UNAUTHORIZED=0if still can't connect, maybe problem is in your api
ChausieOP
Thank you! Made a typo, and it took me a whole day to realize 
