jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
896 stars 222 forks source link

How to use ws4redis in a separate URL address? #184

Open yguarata opened 8 years ago

yguarata commented 8 years ago

I use a proxy service (CloudFlare) that does not support websockets. A workaround is to have a separate address for the websockets (such as ws.myapp.com), that is not behind the proxy. I tested this configuration and noticed that ws4redis was able to connect and send messages to the server, however the messages from the server were not flowing back to the clients. No errors showed up.

Do you have any clue on this? What part of the code should I look for if it is necessary some modification?

Thanks.

jrief commented 8 years ago

I'm not sure if this restriction applies to websockets as well, but Javascript sometimes applies a foreign origin policy.

yguarata commented 8 years ago

No, it does not apply to websockets. =/

During my tests, I needed to modify the following line in order to change the websocket host: https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/context_processors.py#L13

Could this have an impact on the way messages are consumed from redis queue?

yguarata commented 8 years ago

Just found the problem. It concerned with looking for session key in line https://github.com/jrief/django-websocket-redis/blob/master/ws4redis/wsgi_server.py#L54. In the case of cross domains (websocket domain != app domain), it is necessary to inform Django to use the same cookie for these domains, setting the variable SESSION_COOKIE_DOMAIN in settings.py. For instance: SESSION_COOKIE_DOMAIN = '.myapp.co'. For more information, please refer to http://www.pindi.us/blog/migrating-cross-domain-cookies-django.

However, I needed to perform some minor modifications in ws4redis context_processor and settings in order to make it work with cross domains. I intend to do a pull request soon.

yguarata commented 8 years ago

This is fixed by pull request #185