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 3002 and apache is using port 80
so my node server is running on
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 3002 port , so basically
http://example.com/server ---proxying---> http://78.47.222.225:3002
so now when i go to http://example.com/server
i get
Hello World!
which means its working but in my homepage http://example.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://example.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://example.com/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
r.doOpen @ index.js:83
but shouldn't it try the example.com/server/socket.io
? considering i gave http://example.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
const socket = io.connect("http://78.47.222.225:3002" , {transports:['websocket']});
socket.on('connect', function () {
console.log('connected!!!') ;
});
basically
io.connect("http://example.com/server")
tries to connect to
ws://example.com/socket.io
which will fail even tho server works with this address example.com/server
... i think it should connect to ws://example.com/server/socket.io
?
but
io.connect("http://78.47.222.225:3002")
will connect to
ws://78.47.222.225:3002/socket.io
and it works !
proxy setting
<VirtualHost xxx.xxx.xxx.xxx:443 >
.....
.....
<Location /server>
ProxyPass http://localhost:3002/
ProxyPassReverse http://localhost:3002/
</Location>
</VirtualHost>