Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

364
Visualizações
socket.io-client connects with localhost but not with IP

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:
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda