Next.js Discord

Discord Forum

Websocket failed to connect

Unanswered
Chausie posted this in #help-forum
Open in Discord
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

  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