diff options
author | Lachlan Sylvester <lachlan.sylvester@hypothetical.com.au> | 2015-10-14 20:19:36 +1100 |
---|---|---|
committer | Lachlan Sylvester <lachlan.sylvester@hypothetical.com.au> | 2015-10-15 06:29:43 +1100 |
commit | aba40cc0189ac0a3dcc062fb80cfbfceb8694e4c (patch) | |
tree | 430f3d1e1e94e4b1f70bd0254496987d9c6000b1 | |
parent | 60d2f4becbf85bcecd243d9d0a529658d52b24fe (diff) | |
download | rails-aba40cc0189ac0a3dcc062fb80cfbfceb8694e4c.tar.gz rails-aba40cc0189ac0a3dcc062fb80cfbfceb8694e4c.tar.bz2 rails-aba40cc0189ac0a3dcc062fb80cfbfceb8694e4c.zip |
add railtie and set default allowed_request_origins for development
-rw-r--r-- | lib/action_cable.rb | 2 | ||||
-rw-r--r-- | lib/action_cable/railtie.rb | 19 | ||||
-rw-r--r-- | lib/action_cable/server/base.rb | 2 |
3 files changed, 23 insertions, 0 deletions
diff --git a/lib/action_cable.rb b/lib/action_cable.rb index d2c5251634..de1b08f789 100644 --- a/lib/action_cable.rb +++ b/lib/action_cable.rb @@ -17,6 +17,8 @@ require 'em-hiredis' require 'redis' require 'action_cable/engine' if defined?(Rails) +require 'action_cable/railtie' if defined?(Rails) + require 'action_cable/version' module ActionCable diff --git a/lib/action_cable/railtie.rb b/lib/action_cable/railtie.rb new file mode 100644 index 0000000000..0be6d19620 --- /dev/null +++ b/lib/action_cable/railtie.rb @@ -0,0 +1,19 @@ +module ActionCable + class Railtie < Rails::Railtie + config.action_cable = ActiveSupport::OrderedOptions.new + + initializer "action_cable.logger" do + ActiveSupport.on_load(:action_cable) { self.logger ||= ::Rails.logger } + end + + initializer "action_cable.set_configs" do |app| + options = app.config.action_cable + + options.allowed_request_origins ||= "http://localhost:3000" if ::Rails.env.development? + + ActiveSupport.on_load(:action_cable) do + options.each { |k,v| send("#{k}=", v) } + end + end + end +end diff --git a/lib/action_cable/server/base.rb b/lib/action_cable/server/base.rb index 9315a48f20..5b7ddf4185 100644 --- a/lib/action_cable/server/base.rb +++ b/lib/action_cable/server/base.rb @@ -66,5 +66,7 @@ module ActionCable config.connection_class.identifiers end end + + ActiveSupport.run_load_hooks(:action_cable, Base.config) end end |