diff --git a/config/environments/development.rb b/config/environments/development.rb index d8f76fe42..6c7693598 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -67,17 +67,4 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true - - # Automatically inject JavaScript needed for LiveReload - if ENV['RAKE_LIVE_RELOAD'].present? - require 'rack-livereload' - config.middleware.insert_after( - ActionDispatch::Static, - Rack::LiveReload, - no_swf: true, - min_delay: 500, # default 1000 - max_delay: 10_000, # default 60_000 - live_reload_port: 35_738 - ) - end end diff --git a/config/initializers/rack_livereload.rb b/config/initializers/rack_livereload.rb new file mode 100644 index 000000000..2d7a88320 --- /dev/null +++ b/config/initializers/rack_livereload.rb @@ -0,0 +1,34 @@ +if Rails.env.development? && ENV['RAKE_LIVE_RELOAD'].present? + + require 'rack-livereload' + + # strongly inspired by https://github.com/johnbintz/rack-livereload/issues/71#issuecomment-674899405 + module BodyProcessorExtension + def process!(env) + @content_security_policy_nonce = if ActionDispatch::Request.new(env).respond_to?(:content_security_policy_nonce) + ActionDispatch::Request.new(env).content_security_policy_nonce + end + + super + end + + def template + orignal_template = ::File.read(::File.expand_path('../../../../skel/livereload.html.erb', method(:template).super_method.source_location[0])) + nonced_template = orignal_template.gsub(%r{(