ActionCable + Heroku + Custom Domain

My last blog post I discuss how I set up realtime chatting with the new Rails5 ActionCable.

Then I went to launch on heroku — worked perfectly.

Then I pushed to a heroku app with a custom domain name, let’s call it example.com . It didn’t seeing anything subscribing on the custom domain, but if I went to the herokuapp URL, I could see it subscribing the user.

The problem is that the server is still listening on: app-name.herokuapp.com

I searched for days and days for a way to allow the server to listen to the custom URL’s connection, and after it all… it was just a couple simple lines:

heroku config:set RAILS_HOST "http://www.example.com"

And in production.rb

config.action_cable.url = "wss://#{ENV['RAILS_HOST']}/cable"

I hope this helps anyone else who is working with ActionCable on a Heroku custom domain, or white-labeled URL!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s