ruby-on-railsherokuwebsocket-rails

Error during WebSocket handshake: Unexpected response code: 503


I am trying to use websocket rails with angular and heroku. It is working in development but now in production. Here's the server code that publishes the event and the client that listens to it.

#Server
WebsocketRails[channel_name].trigger('new_message', @json)

//Client
var dispatcher = new WebSocketRails(window.location.host + "/websocket");
var channel = dispatcher.subscribe(channel_name);
channel.bind('new_message', function(data) {
  $scope.$apply(function(){
    cr.unread_messages += 1;
  });
});

I'm on SSL in production. I already tried setting

force_ssl = false

in production.rb, but to no avail.

The error I am getting is:

WebSocket connection to 'wss://domain.com/websocket' failed: Error during WebSocket handshake: Unexpected response code: 503

Solution

  • I had the same issue, my app is behind nginx. Check my Nginx configs that worked for me.

    location / {
      proxy_pass http://localhost:8080;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
    }