fanout / django-eventstream

Server-Sent Events for Django
MIT License
664 stars 88 forks source link

CORS Error: How can we allow multiple origins #133

Closed sau0409 closed 7 months ago

sau0409 commented 11 months ago

As per document we can only give single value for EVENTSTREAM_ALLOW_ORIGIN, but in my case I need to allow one more origin. If I try changing EVENTSTREAM_ALLOW_ORIGIN = "*", I get another cors error.

Screenshot from 2023-11-03 18-14-10

jkarneges commented 10 months ago

Hmm, yeah this isn't possible. I suppose the header needs to be dynamically determined based on the request.

One idea is to set the Access-Control-Allow-Origin response header to the value of the request's Host header if EVENTSTREAM_ALLOW_ORIGIN is set to an asterisk. What do you think?

jkarneges commented 7 months ago

Update: the latest version now uses async views instead of channels, which means CORS configuration can now be managed with django-cors-headers.