Closed virangaj closed 4 months ago
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
Please provide the screenshot in broswer or cURL about the headers for both request and response. You can mask the sensitive information. I would like to double confirm is the header properly sent.
For example, is the browser providing the Origin
header.
If you are using reverse proxy in between, please also check if the headers are hide by that proxy. It is often that the proxy is not properly proxy CORS headers and requires some manual config.
This is what I'm getting in my browser
This screenshot is not going to helps. You should provide that contain the headers for both request and response.
I am closing the issue because I believe it is the problem related to socket.io
.
socket.io
used to be overriding the request handling of fastify
, so you should configure the CORS from socket.io
side.
Yes, you are correct... the issue is in socket.io
side, Thank you
Prerequisites
Fastify version
4.27.0
Plugin version
No response
Node.js version
18.18.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
23H2
Description
Description: I am encountering a CORS issue while setting up my Fastify server with Socket.IO. Despite configuring the CORS plugin, my frontend is unable to communicate with the backend due to CORS errors.
Steps to Reproduce:
Expected Behavior: The frontend should be able to communicate with the backend without CORS issues.
Actual Behavior: The frontend is receiving CORS errors when attempting to communicate with the backend.
Fastify Server Code:
Access to XMLHttpRequest at 'http://your-frontend-url.com/chat' from origin 'http://your-frontend-url.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Link to code that reproduces the bug
No response
Expected Behavior
The frontend should be able to communicate with the backend without CORS issues.