Skip to content

Commit fc2ce52

Browse files
committed
Change configuration for ActionCable
See article https://blog.heroku.com/real_time_rails_implementing_websockets_in_rails_5_with_action_cable Requires that PRODUCTION_HOST be set in the ENV of the production environment.
1 parent 4d0dc2d commit fc2ce52

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Your support keeps this project going!
1010

1111
(Want to become a contributor? [Contact us](mailto:contact@shakacode.com) for an Slack team invite! Also, see ["easy" issues](https://github.com/shakacode/react_on_rails/labels/easy) and [issues for the full tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy).)
1212

13+
# React on Rails Pro!
14+
Justin is currently working with a couple contributors on some new private examples that incorporate ShakaCode's best practices for industrial strength apps using React on Rails. If you're interested in getting access to these and/or contributing, [email justin@shakacode.com](mailto:justin@shakacode.com). Technologies will include Webpack v2, Yarn, CSS Modules, Bootstrap v4, Redux-Saga, Normalizr, Reselect, etc.
15+
1316
# ShakaCode Community
1417
Please [Subscribe](https://app.mailerlite.com/webforms/landing/l1d9x5) to keep in touch with Justin Gordon and [ShakaCode](http://www.shakacode.com/). I intend to send a monthly summary including announcements of new releases of bootstrap-loader and React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials. Subscribers will also have access to **exclusive content**, including tips and examples.
1518

@@ -38,8 +41,8 @@ For more testimonials, see [Live Projects](https://github.com/shakacode/react_on
3841

3942
## NEWS
4043

41-
* Action Cable was recently added in [PR #355](https://github.com/shakacode/react-webpack-rails-tutorial/pull/355).
42-
* We made react-native client: [shakacode/reactrails-react-native-client](https://github.com/shakacode/reactrails-react-native-client/)
44+
* Action Cable was recently added in [PR #355](https://github.com/shakacode/react-webpack-rails-tutorial/pull/355). See [PR#360](https://github.com/shakacode/react-webpack-rails-tutorial/pull/360) for additional steps to make this work on Heroku. Note, you need to be running redis. We installed the free Heroku redis add-on.
45+
* We made a react-native client: [shakacode/reactrails-react-native-client](https://github.com/shakacode/reactrails-react-native-client/). If you want to hack on this with us, [email justin@shakacode.com](mailto:justin@shakacode.com).
4346
* We have [some other open PRs](https://github.com/shakacode/react-webpack-rails-tutorial/pulls) of things we may soon be incorporating, including localization and action cable! Stay tuned! If you have opinions of what should or should not get merged, get in touch with [justin@shakacode.com](mailto:justin@shakacode.com).
4447

4548
This tutorial app demonstrates advanced functionality beyond what's provided by the React on Rails generators, mostly in the area of Webpack and React usage. Due to the architecture of placing all client side assets in the `/client` directory, React on Rails supports just about anything that Webpack and JavaScript can do, such as:

config/cable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
22
production:
33
adapter: redis
4-
url: <%= ENV["REDISCLOUD_URL"] %>
4+
url: <%= ENV["REDIS_URL"] %>
55

66
development:
77
adapter: redis

config/environments/production.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2+
class ChatActionCable
3+
def initialize(app, _options = {})
4+
@app = app
5+
end
6+
7+
def call(env)
8+
if Faye::WebSocket.websocket?(env)
9+
ActionCable.server.call(env)
10+
else
11+
@app.call(env)
12+
end
13+
end
14+
end
15+
116
Rails.application.configure do
217
# Settings specified here will take precedence over those in config/application.rb.
318

@@ -38,9 +53,6 @@
3853
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
3954
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
4055

41-
# Action Cable endpoint configuration
42-
# config.action_cable.url = 'wss://example.com/cable'
43-
4456
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
4557
config.force_ssl = true
4658

@@ -85,4 +97,9 @@
8597

8698
# Do not dump schema after migrations.
8799
config.active_record.dump_schema_after_migration = false
100+
101+
# Action Cable endpoint configuration
102+
103+
config.action_cable.url = "wss://#{ENV['PRODUCTION_HOST']}/cable"
104+
config.action_cable.allowed_request_origins = ["https://#{ENV['PRODUCTION_HOST']}"]
88105
end

0 commit comments

Comments
 (0)