Skip to content

Instantly share code, notes, and snippets.

@dodeja
Created May 7, 2016 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodeja/f349fb8d8b372a7b0e1b707b75c0ccd5 to your computer and use it in GitHub Desktop.
Save dodeja/f349fb8d8b372a7b0e1b707b75c0ccd5 to your computer and use it in GitHub Desktop.
Websockets using Rails 5 beta 2, ActionCable and Puma on Heroku
# 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
# 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
// 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