I am struggling to find out the problem with connecting to server.
With localhost, it's working fine, but when I am changing the host to IP address, it throws an error and what's strange for me, it adds /socket.io as a pathname.
'ws://134.122.32.44:8290/socket.io/?EIO=4&transport=websocket'
"socket.io-client": "^4.3.2", "socket.io": "^4.4.1",
This is a server config part.
const { Server } = require("socket.io");
this.socket = new Server(port, {
cors: {
origin: '*'
}
});
And this is the client config
this.socket = io(`ws://${wsHost}:${wsPort}`, {
timeout: 15000,
withCredentials: true,
reconnectionDelayMax: 10000,
transports: ['websocket', 'polling'],
});
If wsHost is localhost it is working fine, but not with an actual IP address.
I am new to sockets and just want to find out where do I need to find the issue.
Is it related to backend configs or client ?
UPDATED
const { Server } = require("socket.io");
this.socket = new Server(port, {
cors: {
origin: '*'
},
path: "/api",
});
And in client also.
this.socket = io(`ws://${wsHost}:${wsPort}`, {
timeout: 15000,
path: "/api",
withCredentials: true,
reconnectionDelayMax: 10000,
transports: ['websocket', 'polling'],
});
Here is the Nginx server configs
server {
listen 80;
listen [::]:80;
server_name _;
access_log /var/log/nginx/api.access.log;
error_log /var/log/nginx/api.error.log debug;
location /api {
proxy_pass http://134.122.32.44:7878;
}
location /var/www/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://134.122.32.44:8290;
}
}
Error is here
websocket.js:50 WebSocket connection to 'ws://134.122.32.44:8290/api/?EIO=4&transport=websocket' failed: