socketio / socket.io-admin-ui

Admin UI for Socket.IO
https://admin.socket.io
MIT License
358 stars 95 forks source link

cors error #35

Open GonnaWooh opened 2 years ago

GonnaWooh commented 2 years ago

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?

darrachequesne commented 2 years ago

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?

GonnaWooh commented 2 years ago

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.

darrachequesne commented 2 years ago

@GeonwooDev have you eventually found a solution?

GonnaWooh commented 2 years ago

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

MehdiMamas commented 2 years ago

any updates on this?

darrachequesne commented 2 years ago

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

From my understanding there are two possible explanations:

Could you please share what gets printed to the console?

Abolfazl-ghodrati-k commented 1 year ago

did you find the answer

neobie commented 1 year ago

Getting error as well.

darrachequesne commented 1 year ago

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

Does that help?

LordPhyre commented 6 months ago

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 commented 6 months ago

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

szymonc commented 6 months ago

Same issue