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

327
Vistas
Why does my web socket call fail when server has a base url?

I am facing a strange problem. I have a express backend server. When I do not have a base URL for my backend, the ws calls are working fine:

enter image description here

But, if I add a base URL ( for example, adding /api/ as part of the url ), my connections fail:

enter image description here

This the part of my backend code:

const easyrtc = require("open-easyrtc"); // EasyRTC external module    
// Start Express http server
const webServer = http.createServer(app);

const socketIo = require("socket.io")(webServer, {path: '/api/'}); // web socket external module

// Start Socket.io so it attaches itself to Express server
const socketServer = socketIo.listen(webServer, { "log level": 1 });
easyrtc.listen(app, socketServer, null, (err, rtcRef) => {
  console.log("Initiated");

  rtcRef.events.on(
    "roomCreate",
    (appObj, creatorConnectionObj, roomName, roomOptions, callback) => {
      console.log("roomCreate fired! Trying to create: " + roomName);

      appObj.events.defaultListeners.roomCreate(
        appObj,
        creatorConnectionObj,
        roomName,
        roomOptions,
        callback
      );
    }
  );
});

// Listen on port
webServer.listen(port, () => {
  console.log("listening");
});

Why does this happen and how can I fix it? I have been at a loss on this for a week now.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

https://socket.io/docs/v4/server-options/

The /socket.io/ is default value for path option. If you use {path: '/api/'} option, then you should call

ws://localhost:3000/api/?EIO=3....

instead of ws://localhost:3000/api/socket.io/?EIO=3...

over 4 years ago · Santiago Trujillo 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