cant connect to node server via socket.io after mapping an address to port

im very new to nodejs so bare with me

so i have a nodejs server which i use to inject live data to my php/laravel website via socket.io i run my nodejs server in port 3001 and apache is using port 80

so my node server is running on

http://bia2roll.com:3001

so i noticed clients who use vpn or proxy cant connect to my nodeserver address and websocket connection fails for them

after asking in this question it was suggested its bcuz vpn is fire walling unusual ports

nodejs server doesn't respond when clients use vpn or proxy

so i maped a address to 3001 port , so basically

http://bia2roll.com/server ---proxying---> http://bia2roll.com:3001

so now when i go to http://bia2roll.com/server i get

Cannot GET /

which means its working but in my homepage http://bia2roll.com when i try to connect to the server via socket.io it fails ... homepage source

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js" ></script>

</head>
<body>
<script>

    const  socket = io.connect("http://bia2roll.com/server" ,  {transports:['websocket']});

    socket.on('connect', function () {
        
        console.log('connected!!!') ; 
        
    });

</script>

</body>
</html>

not sure why is this happening but in my console i see it trying to connect to this address

WebSocket connection to 'ws://bia2roll.com/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
r.doOpen @ index.js:83

but shouldnt it try the bia2roll.com/server/socket.io ? considering i gave http://bia2roll.com/server to io.connect ?

it works fine when i try connecting via ip:port ... try this address to connect via ip:port instead of proxy address

http://bia2roll.com?port=1



Read more here: https://stackoverflow.com/questions/64413179/cant-connect-to-node-server-via-socket-io-after-mapping-an-address-to-port

Content Attribution

This content was originally published by hretic at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: