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

320
Views
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 answers
Answer question

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