'Websocket connection error : Does not return a 101 changing protocal when using from different path

I am using easy-rtc with socket.io for multiuser experience in my metaverse project. We maintain the connection in socket.io using polling and web-socket. I am facing problem in web-socket connection when I am trying to give path to the socket.io.

Firstly, I am putting forward the code where I am not using any path. You can get the complete code from here. https://github.com/networked-aframe/networked-aframe/blob/master/server/easyrtc-server.js

Code without Path(1)

Code without Path(2)

Code without Path(3)

The web-socket connection request which I am getting from this code is giving me a 101 changing protocols as expected.

Web-socket connection Request (working Fine)

I am even getting the response for the web-socket request as connecting in the Postman.

Postman web-socket request

Now, My backend is working at localhost:3333/api/ . I am trying to change the path of socket.io in the client and server as shown in the images below. but I am not getting the 101 changing protocol response from web-socket connection request. This is the code after path change.

This is the client side code:setting socket URL path in client side

This is the backend code : Setting path for socket.io in backend

This is the response which I am getting when running the code after doing the path changes. Web-Socket not giving 101 changing protocols

When I am trying to hit the web-socket request in the postman also I am not getting any connection. One observation I have made is that in the request URL, it is not taking the localhost:3333/api/ path. (If this is the issue, suggest any work arounds for this.) Web-socket request in postman

Without getting the web-socket connection, the server is not efficient for communication.

Anyone suggest working solutions for this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source