Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
Error de Socket io CORS No se puede conectar el cliente al servidor Nodejs a través de Socket.io

Tengo un servidor Nodejs en funcionamiento al que llego a localhost: 4000 (funciona bien). Estoy tratando de conectar un cliente a través de socketio al servidor fuera de Nodejs. Desde localhost:8888/page (aplicación MAMP) a un socket, pero ERR_FAILED 200 en la consola. Hay algo que impide conectarse a un enchufe.

Servidor Nodejs.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"); });

una página web fuera de la aplicación de nodo:

 <!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>

Por favor ayuda..

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!