I followed explanations from django-channels tutorial and was able to run a chat locally.
However, it does not work in production.
Here is the output from debugger :
WebSocket connection to 'wss://www.example.com/ws/chat/lobby/' failed: Error during WebSocket handshake: Unexpected response code: 404
(anonymous) @ (index):23
(index):40 Chat socket closed unexpectedly
chatSocket.onclose @ (index):40
(index):56 WebSocket is already in CLOSING or CLOSED state.
document.querySelector.onclick @ (index):56
document.querySelector.onkeyup @ (index):47
Here is the javascript I use to try having it work with our https website :
const roomName = JSON.parse(document.getElementById('room-name').textContent);
var loc = window.location;
var wsStart = 'ws://';
if (loc.protocol === 'https:') {
wsStart = 'wss://'
}
const chatSocket = new WebSocket(
wsStart
+ window.location.host
+ '/ws/chat/'
+ roomName
+ '/'
);
I use redisgreen for redis :
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('redis://:xxxxxxx@great-whale-0077a76ca7.redisgreen.net:11042/')]
},
},
}
The rest of the code is as per the tutorial.
I am not sure how I should address this issue. Any clue ? Is it required to implement Daphne to run channels in production ? Or did I do something wrong ?
Thanks a lot for your help.