0

I have a working rails 5 app with ActionCable on my localhost, and I'm trying to deploy it to heroku. When accessing the page where the chat room is, I can see in chrome's console:

WebSocket connection to 'wss://full-beyond-9816.herokuapp.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

I did setup Redis and the Redis addon on heroku. Here is the production part of my cable.yml file:

production: &production
  :url: redis://redistogo:4140ce7f3e7493bd1b12@porgy.redistogo.com:9463/
  :host: tarpon.redistogo.com
  :port: 10272
  :password: 12e348ac10ca002879ce7d85daf0bb0
  :inline: true
  :timeout: 1

Here is my room.coffee file:

(function() {
  this.App || (this.App = {});

  App.cable = ActionCable.createConsumer();

}).call(this);

Setting up ActionCable on heroku seems tricky, and every post I've found on the subject is either using Phusion Passenger (I'm using Puma), or with a pretty old version of ActionCable (I'm using the latest beta of Rails 5).

How should I set this up ? Thanks for your time and help

Graham Slick
  • 6,692
  • 9
  • 51
  • 87

1 Answers1

5

Hard to tell from your error. I did manage to deploy ActionCable on Heroku using Redis addon and Puma. Though I have to admit, since ActionCable is super new, it's hard to get any support. I had to play around to make it work.

In your case, you probably have a cors issue. Look at the file config/environments/production.rb, uncomment the following section and add your heroku app name:

  # Action Cable endpoint configuration
  config.action_cable.url = 'wss://yourappname.herokuapp.com/cable'
  config.action_cable.allowed_request_origins = [ 'https://yourappname.herokuapp.com', /http:\/\/yourappname.herokuapp.com.*/ ]

Just in case, here my cable.yml file:

# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
production:
  adapter: redis
  url: add-hereyour-redis-url-from-heroku-redis-to-go-addon

development:
  adapter: async

test:
  adapter: async

Also don't forget to add the gem Redis to run Action Cable in production. And regarding your room.coffee file, fyi, it should simply look like this (meaning the client-side needs to setup a consumer instance of this connection):

#= require action_cable
#= require_self
#= require_tree .

@App = {}
App.cable = ActionCable.createConsumer()
doem
  • 108
  • 5