title: How to resolve “Error during WebSocket handshake: Unexpected response code: 503” error in a Django Channels Heroku app?
body: <p>The error in the console :</p>
  <pre><code>  app.e05f6d1a6569.js:105 WebSocket connection to 'wss://domecode.com/wss?session_key=${sessionKey}' failed: Error during WebSocket handshake: Unexpected response code: 503
      (anonymous) @ app.e05f6d1a6569.js:105
      mightThrow @ jquery.js:3762
      process @ jquery.js:3830
  </code></pre>
  <p>I'm running a Django Channels app ( Messaging app ) on Heroku using Daphne. All the files that correspond to this problem are included in this question.</p>
  <p>routing.py - messaging app</p>
  <pre class="lang-py prettyprint-override"><code>from messaging import consumers
  from django.urls import re_path
  
  websocket_urlpatterns = [
      re_path(r'^ws$', consumers.ChatConsumer),
  ]
  </code></pre>
  <p>app.js - snipped of the websocket part of the app.js file</p>
  <pre class="lang-js prettyprint-override"><code>var ws_scheme = window.location.protocol == 'https:' ? 'wss' : 'ws';
  var socket = new WebSocket(ws_scheme + '://' + window.location.host + '/' + ws_scheme + '?session_key=${sessionKey}');
  </code></pre>
  <p>asgi.py - project's asgi</p>
  <pre class="lang-py prettyprint-override"><code>import os
  import django
  # from django.core.asgi import get_asgi_application
  from channels.routing import get_default_application
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'domecode.settings')
  django.setup()  # to deploy with asgi when using channels
  application = get_default_application() 
  </code></pre>
  <p>Procfile</p>
  <pre><code>release: python3 manage.py makemigrations &amp;&amp; python3 manage.py migrate
  web: daphne domecode.asgi:application --port $PORT --bind 0.0.0.0 -v2
  worker: python3 manage.py runworker channel_layer -v2 
  </code></pre>
  <p>Django Settings snippet for CHANNEL_LAYERS - REDIS_URL is an env variable in Heroku.</p>
  <pre><code>CHANNEL_LAYERS = {
      'default': {
          'BACKEND': 'channels_redis.core.RedisChannelLayer',
          'CONFIG': {
              &quot;hosts&quot;: [config('REDIS_URL')],
          },
      },
  }
  </code></pre>
  <p>Any information on what went wrong here?</p>
  <p>Sidenote: It works perfectly fine in the development server however it gives the error mentioned at the top in the production server at <a href="https://domecode.com/chat/" rel="nofollow noreferrer">https://domecode.com/chat/</a>.</p>
  <p>When I send a message on the production server, it gives an error in the console and I don't see my message that was sent unless I reload the page. I've tried looking for similar questions everywhere but none of them were answered in a way that would work for me.</p>