Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
Socket io CORS error Can't Connect Client To Nodejs Server Through Socket.io

I have working Nodejs server which I reach at localhost:4000 (working fine). I'm trying to connect a client through socketio to server outside of Nodejs. From localhost:8888/page (MAMP app) to a socket, but I'm getting ERR_FAILED 200 in console. There's something preventing from connecting to a socket.

Nodejs server.js:

import fetch from 'node-fetch';
import express from 'express';
const app = express();
import http from 'http';
const server = http.createServer(app);
import {Server} from 'socket.io';
const io = new Server(server);
import mysql from 'mysql';

{...}

server.listen('4000', () => {
  console.log("Server running on port 4000");
});

a webpage outside of node app:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
  <script src="https://cdn.socket.io/4.4.1/socket.io.min.js" integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H" crossorigin="anonymous">
  </script>
  </script>
</head>
<body>

<script src="http://localhost:4000/socket.io/socket.io.js"></script>
<script>

const socket = io.connect('http://localhost:4000/');


</script>
</body>
</html>

Please help..

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

https://socket.io/docs/v3/handling-cors/

const io = require("socket.io")(httpServer, {
  cors: {
    origin: "https://example.com",
    methods: ["GET", "POST"]
  }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda