Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

multiple CORS values in socketio requests error when using CORSMiddleware #28

Open
chinchaun opened this issue Dec 31, 2021 · 2 comments

Comments

@chinchaun
Copy link

Hello humans,
I faced an issue when I was trying to use fastapi-socketio and the CORSMiddleware

app = FastAPI()
sio = SocketManager(app=app)

# CORS
# Set all CORS enabled origins
if config.BACKEND_CORS_ORIGINS:
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )

and this error was showing up
Screen Shot 2021-12-30 at 23 13 11

The workaround I found was to set to an empty list the cors_allowed_origins parameter on the SocketManager to prevent the duplication of the values
Solution

app = FastAPI()
sio = SocketManager(app=app, cors_allowed_origins=[])

# CORS
# Set all CORS enabled origins
if config.BACKEND_CORS_ORIGINS:
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )

The solution was taken from here

if I have some time, I will try to fix it,
Cheers

@niteshgaba
Copy link

Hi @chinchaun ,

I am also facing the same issue but not able to connect after using the same solution. Any insights ?

@chinchaun
Copy link
Author

Hey @niteshgaba,
mmm I don't know how to help you, I remember I have to dig into the source code and the issue mentioned above to find the workaround and I just worked.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants