Skip to content

cors error #35

Open
Open

Description

@GonnaWooh

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?

Activity

  1. darrachequesne commented on Feb 17, 2022

    @darrachequesne
    Member

    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?

  2. GonnaWooh commented on Feb 18, 2022

    @GonnaWooh
    Author

    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.

  3. darrachequesne commented on Jun 23, 2022

    @darrachequesne
    Member

    @GeonwooDev have you eventually found a solution?

  4. GonnaWooh commented on Jul 7, 2022

    @GonnaWooh
    Author

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

  5. MehdiMamas commented on Sep 18, 2022

    @MehdiMamas

    any updates on this?

  6. darrachequesne commented on Sep 19, 2022

    @darrachequesne
    Member

    @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?

  7. Abolfazl-ghodrati-k commented on Feb 4, 2023

    @Abolfazl-ghodrati-k

    did you find the answer

  8. neobie commented on May 11, 2023

    @neobie

    Getting error as well.

  9. darrachequesne commented on May 23, 2023

    @darrachequesne
    Member

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

    Does that help?

  10. TedKaczynskisCousin commented on Apr 29, 2024

    @TedKaczynskisCousin

    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)

  11. TedKaczynskisCousin commented on Apr 29, 2024

    @TedKaczynskisCousin

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

  12. szymonc commented on May 17, 2024

    @szymonc

    Same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions