diff --git a/app/middleware/chat_action_cable.rb b/app/middleware/chat_action_cable.rb new file mode 100644 index 0000000..297db2f --- /dev/null +++ b/app/middleware/chat_action_cable.rb @@ -0,0 +1,13 @@ +class ChatActionCable < ActionCable::Connection::WebSocket + def initialize(app, options={}) + @app = app + end + + def call(env) + if ::WebSocket::Driver.websocket?(env) + ActionCable.server.call(env) + else + @app.call(env) + end + end +end diff --git a/config/environments/production.rb b/config/environments/production.rb index 54cb92d..2129e26 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,6 +14,9 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true + config.middleware.use ChatActionCable + config.web_socket_server_url = "wss://rails-web-sockets.herokuapp.com/" + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true