Skip to content

Commit

Permalink
Detach actioncable from the WebsocketServer and run it with the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Dec 16, 2018
1 parent 4591309 commit d7d2824
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
6 changes: 4 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ class Application < Rails::Application

# Disable ActionCable's request forgery protection
# This is basically matching a set of allowed origins which is not good for us
# Our own origin-host forgery protection is implemented in lib/websocket_server.rb
Rails.application.config.action_cable.disable_request_forgery_protection = true
config.action_cable.disable_request_forgery_protection = false
# Matching the origin against the HOST header is much more convenient
config.action_cable.allow_same_origin_as_host = true
config.action_cable.mount_path = '/ws/notifications'

# Customize any additional options below...

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
if Rails.env.development? && defined?(Rails::Server)
logger = Logger.new(STDOUT)
logger.level = Logger.const_get(::Settings.log.level_websocket.upcase)
mount WebsocketServer.new(:logger => logger) => '/ws'
mount WebsocketServer.new(:logger => logger) => '/ws/console'
end
end
3 changes: 0 additions & 3 deletions lib/websocket_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ def initialize(options = {})
end

def call(env)
# Pass the request to ActionCable if it is for notifications
return ActionCable.server.call(env) if env['REQUEST_URI'].start_with?('/ws/notifications') && ::Settings.server.asynchronous_notifications

exp = %r{^/ws/console/([a-zA-Z0-9]+)/?$}.match(env['REQUEST_URI'])
if WebSocket::Driver.websocket?(env) && same_origin_as_host?(env) && exp.present?
@logger.info("Remote console connection initiated with secret #{exp[1]}")
Expand Down
9 changes: 0 additions & 9 deletions spec/lib/websocket_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
let(:env) { {'REQUEST_URI' => "/ws/#{url}", 'rack.hijack' => hijack} }

describe '#call' do
context 'notifications' do
let(:url) { 'notifications' }

it 'calls actioncable' do
expect(ActionCable.server).to receive(:call).with(env)
subject.call(env)
end
end

context 'remote console' do
let(:url) { 'console/12345' }

Expand Down

0 comments on commit d7d2824

Please sign in to comment.