@@ -876,6 +876,10 @@ For a full list of all configuration options, see the
876
876
877
877
## Running Standalone Cable Servers
878
878
879
+ Action Cable can either run as part of your Rails application, or as
880
+ a standalone server. In development, running as part of your Rails app
881
+ is generally fine, but in production you should run it as a standalone.
882
+
879
883
### In App
880
884
881
885
Action Cable can run alongside your Rails application. For example, to
@@ -890,14 +894,15 @@ end
890
894
` ` `
891
895
892
896
You can use ` ActionCable .createConsumer ()` to connect to the cable
893
- server if ` action_cable_meta_tag` is invoked in the layout. Otherwise, A path is
897
+ server if [ ` action_cable_meta_tag` ][] is invoked in the layout. Otherwise, a path is
894
898
specified as first argument to ` createConsumer` (e.g. ` ActionCable .createConsumer (" /websocket" )` ).
895
899
896
900
For every instance of your server you create, and for every worker your server
897
901
spawns, you will also have a new instance of Action Cable, but the Redis or
898
902
PostgreSQL adapter keeps messages synced across connections.
899
903
900
904
[` config .action_cable .mount_path ` ]: configuring.html#config-action-cable-mount-path
905
+ [` action_cable_meta_tag` ]: https://api.rubyonrails.org/classes/ActionCable/Helpers/ActionCableHelper.html#method-i-action_cable_meta_tag
901
906
902
907
### Standalone
903
908
@@ -913,14 +918,24 @@ Rails.application.eager_load!
913
918
run ActionCable .server
914
919
` ` `
915
920
916
- Then you start the server using a binstub in ` bin / cable ` ala :
921
+ Then to start the server:
917
922
918
923
` ` `
919
- #! / bin/ bash
920
924
bundle exec puma - p 28080 cable/ config .ru
921
925
` ` `
922
926
923
- The above will start a cable server on port 28080.
927
+ This starts a cable server on port 28080. To tell Rails to use this
928
+ server, update your config:
929
+
930
+ ` ` ` ruby
931
+ # config/ environments/ development .rb
932
+ Rails .application .configure do
933
+ config .action_cable .mount_path = nil
934
+ config .action_cable .url = " ws://localhost:28080" # use wss: // in production
935
+ end
936
+ ` ` `
937
+
938
+ Finally, ensure you have [configured the consumer correctly](#consumer-configuration).
924
939
925
940
### Notes
926
941
0 commit comments