Getting this to work wasn't the easiest of processes. I wasted a bit of time using the incorrect actioncable npm package. The correct one is https://www.npmjs.com/package/actioncable.
In Rails, you need to add the following to allow connections from not-port-3000 in development mode:
# config/initializers/cable.rb
if Rails.env.development?
Rails.application.config.action_cable.allowed_request_origins = ['http://localhost:5000', 'http://localhost:3000']
end
Notes:
- I'm using create-react-app
- You
npm install actioncable --save
to install the correct actioncable package. Do not installaction-cable
by mistake. - You can run it on not-port 3000 by
PORT=5000 npm start
- I'm not authenticating the user at all; Rails wants you to do this with signed cookies, but this would be more difficult with auth tokens, etc.