socket.io-admin-ui icon indicating copy to clipboard operation
socket.io-admin-ui copied to clipboard

cors error

Open GonnaWooh opened this issue 3 years ago • 12 comments

I want to connect client web page for socketIO and admin-ui to socketIO server. But the error appears.

When I use this code below, the client web disconnects with cors error.

const io = new Server(httpServer, { cors: { origin: "https://admin.socket.io", }, }); instrument(io, { auth: false, });

Of course, I did like this, and "xhr poll error" happens on admin-ui.

const io = new Server(httpServer, { cors: { origin: "", // and I did ["https://admin.socket.io",""] instead of this }, }); instrument(io, { auth: false, });

does admin-ui supports only local environment?

GonnaWooh avatar Feb 13 '22 10:02 GonnaWooh

It seems you are missing the credentials: true part:

const { createServer } = require("http");
const { Server } = require("socket.io");
const { instrument } = require("@socket.io/admin-ui");

const httpServer = createServer();

const io = new Server(httpServer, {
  cors: {
    origin: ["https://admin.socket.io"],
    credentials: true
  }
});

instrument(io, {
  auth: false
});

httpServer.listen(3000);

Reference: https://socket.io/docs/v4/admin-ui/#server-side

Could you please check?

darrachequesne avatar Feb 17 '22 06:02 darrachequesne

It seems you are missing the credentials: true part:

const { createServer } = require("http");
const { Server } = require("socket.io");
const { instrument } = require("@socket.io/admin-ui");

const httpServer = createServer();

const io = new Server(httpServer, {
  cors: {
    origin: ["https://admin.socket.io"],
    credentials: true
  }
});

instrument(io, {
  auth: false
});

httpServer.listen(3000);

Reference: https://socket.io/docs/v4/admin-ui/#server-side

Could you please check?

My mistake. The line "credentials: true" is not there, but I wrote it already.

GonnaWooh avatar Feb 18 '22 10:02 GonnaWooh

@GeonwooDev have you eventually found a solution?

darrachequesne avatar Jun 23 '22 13:06 darrachequesne

@darrachequesne No, I'm not using admin-ui, but only socketIO.

GonnaWooh avatar Jul 07 '22 13:07 GonnaWooh

any updates on this?

MehdiMamas avatar Sep 18 '22 00:09 MehdiMamas

@MehdiMamas unfortunatly I am not able to reproduce the issue.

From my understanding there are two possible explanations:

  • either the cors configuration is incorrect (which does not seem to be the case here)
  • or the UI is not able to reach the Socket.IO server

Could you please share what gets printed to the console?

darrachequesne avatar Sep 19 '22 07:09 darrachequesne

did you find the answer

Abolfazl-ghodrati-k avatar Feb 04 '23 10:02 Abolfazl-ghodrati-k

Getting error as well.

neobie avatar May 11 '23 10:05 neobie

I have added a few examples in the documentation about the cors option: https://socket.io/docs/v4/server-options/#cors

Does that help?

darrachequesne avatar May 23 '23 12:05 darrachequesne

same issue here. even with origin: "*" im getting GET http://localhost:8080/socket.io/?EIO=4&transport=polling&t=Oyga8kN net::ERR_FAILED 404 (Not Found)

LordPhyre avatar Apr 29 '24 15:04 LordPhyre

I have also tried everything in this thread, to no avail.

LordPhyre avatar Apr 29 '24 15:04 LordPhyre

Same issue

szymonc avatar May 17 '24 11:05 szymonc