9

I am trying to get ActionCable work on a subdomain.

the problem is that as soon as I am changing the following line

config.action_cable.mount_path = '/'

The app isn't working anymore. But ActionCable works on a subdomain. Is there any solution to run ActionCable on a subdomain without a subdir like /cable?

DjangoSi
  • 395
  • 2
  • 4
  • 16

1 Answers1

3

It looks like you'll need to run it as a standalone server if you're not using an in-app server with a sub-uri: https://github.com/rails/rails/tree/master/actioncable#consumer-configuration

You can specify the cable url like so:

config.action_cable.url = 'ws://cable.example.com:28080'

The cable server(s) is separated from your normal application server. It's still a Rack application, but it is its own Rack application. The recommended basic setup is as follows:

# cable/config.ru
require_relative '../config/environment'
Rails.application.eager_load!

run ActionCable.server

Then you start the server using a binstub in bin/cable ala:

#!/bin/bash
bundle exec puma -p 28080 cable/config.ru

https://github.com/rails/rails/tree/master/actioncable#standalone

jemminger
  • 5,133
  • 4
  • 26
  • 47
  • It depends on how you configure the cable server. I've added that info to the answer – jemminger Aug 29 '17 at 14:29
  • "It looks like you'll need to run it as a standalone server if you're not using an in-app server with a sub-uri" The link you mentioned doesn't seem to work anymore. Could you elaborate a bit more? – Luis Vasconcellos Dec 31 '19 at 20:46
  • @LuisVasconcellos Looks like it moved here: https://edgeguides.rubyonrails.org/action_cable_overview.html#running-standalone-cable-servers – jemminger Jan 02 '20 at 15:32