Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS error in latest release #3685

Closed
saifulshihab opened this issue Nov 9, 2020 · 7 comments
Closed

CORS error in latest release #3685

saifulshihab opened this issue Nov 9, 2020 · 7 comments
Labels
question Further information is requested

Comments

@saifulshihab
Copy link

Older version of socket.io just works fine, but the latest release shows CORS error when trying to connect front to back. I also added CORS middleware to the server but it's not working. But when I switch back to the older version of socket then it's just working nicely.

image

@marovargovcik
Copy link

Hi, I believe this is because documentation does not reflect the change that was made with 3.0 release.
Please see this link https://socket.io/docs/migrating-from-2-x-to-3-0/, section CORS handling.

Not gonna lie, it is kind of a bummer. Started playing with socket.io just today and right away there are road blocks. I would downgrade to 2.x but it seems that documentation does not have versioning.

@darrachequesne
Copy link
Member

Hi! Sorry for that, the documentation is in the process of being updated for v3.

I've added a section about CORS here: https://socket.io/docs/v3/handling-cors/

Could you please check if that's clear enough?

@darrachequesne darrachequesne added the question Further information is requested label Nov 11, 2020
@saifulshihab
Copy link
Author

@darrachequesne thanks, it's solved!

@quindo
Copy link

quindo commented Nov 11, 2020

This might cause problems for people with glitch.me projects. When upgrading the to v3 the glitch.me projects start replying with the error saifulshihab posted. However it appears that CORS is against glitch.me and AWS's TOS and will get a projected removed. Is there a way to run the v3 framework without including CORS?

I do not fully understand what CORS is and why it is a problem. I am just trying to piece together a plan.

@jennschiffer
Copy link

Hi @quindo - just wanted to clarify that enabling CORS is not against Glitch's TOS. Some users were using particular npm packages like CORS-anywhere for malicious reasons and that is against our TOS.

@saifulshihab
Copy link
Author

for those who face the problem:-

// server-side
const io = require("socket.io")(httpServer, {
  cors: {
    origin: "https://example.com",
    methods: ["GET", "POST"],
    allowedHeaders: ["my-custom-header"],
    credentials: true
  }
});

// client-side
const io = require("socket.io-client");
const socket = io("https://api.example.com", {
  withCredentials: true,
  extraHeaders: {
    "my-custom-header": "abcd"
  }
});

@darrachequesne
Copy link
Member

I think this can now be closed. Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants