Created
May 7, 2016 15:34
-
-
Save dodeja/f349fb8d8b372a7b0e1b707b75c0ccd5 to your computer and use it in GitHub Desktop.
Websockets using Rails 5 beta 2, ActionCable and Puma on Heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should be in /app/middleware/ | |
require 'websocket/driver' | |
class ActionCableHeroku | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket. | |
production: | |
adapter: redis | |
url: <%= ENV['REDIS_URL'] %> | |
local: &local | |
adapter: redis | |
url: redis://localhost:6379 | |
development: *local | |
test: *local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/environments/production.rb | |
Rails.application.configure do | |
config.middleware.use ActionCableHeroku | |
config.action_cable.log_tags = [ | |
-> request { request.env['bc.account_id'] || "no-account" }, | |
:action_cable, | |
-> request { request.uuid } | |
] | |
config.action_cable.allowed_request_origins = %w( | |
http://www.terminal49.com | |
http://localhost:3000 | |
) | |
# ... | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment