Skip to content

Commit

Permalink
Change configuration for ActionCable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justin808 committed Feb 15, 2017
1 parent 4d0dc2d commit 50a69df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Your support keeps this project going!

(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).)

# React on Rails Pro!
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.

# ShakaCode Community
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.

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

## NEWS

* Action Cable was recently added in [PR #355](https://github.com/shakacode/react-webpack-rails-tutorial/pull/355).
* We made react-native client: [shakacode/reactrails-react-native-client](https://github.com/shakacode/reactrails-react-native-client/)
* 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.
* 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 use, [email justin@shakacode.com](mailto:justin@shakacode.com).
* 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).

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:
Expand Down
2 changes: 1 addition & 1 deletion config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
production:
adapter: redis
url: <%= ENV["REDISCLOUD_URL"] %>
url: <%= ENV["REDIS_URL"] %>

development:
adapter: redis
Expand Down
23 changes: 20 additions & 3 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@

class ChatActionCable
def initialize(app, _options = {})
@app = app
end

def call(env)
if Faye::WebSocket.websocket?(env)
ActionCable.server.call(env)
else
@app.call(env)
end
end
end

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down Expand Up @@ -38,9 +53,6 @@
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Action Cable endpoint configuration
# config.action_cable.url = 'wss://example.com/cable'

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

Expand Down Expand Up @@ -85,4 +97,9 @@

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Action Cable endpoint configuration

config.action_cable.url = "wss://#{ENV['PRODUCTION_HOST']}/cable"
config.action_cable.allowed_request_origins = ["https://#{ENV['PRODUCTION_HOST']}"]
end

0 comments on commit 50a69df

Please sign in to comment.