Skip to content

Commit

Permalink
added middleware for run Websockets with ActionCable on production
Browse files Browse the repository at this point in the history
Signed-off-by: Kapil Chouhan <kpl.chouhan99@gmail.com>
  • Loading branch information
kapilchouhan committed Mar 8, 2020
1 parent 27afa30 commit d67ff32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/middleware/chat_action_cable.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d67ff32

Please sign in to comment.