diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md index fdb0f143f485f562bcec6522facb708d5d087bb4..1475a7a78651f506deefa27baac887e1ba16ea21 100644 --- a/activestorage/CHANGELOG.md +++ b/activestorage/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add `config.active_storage.draw_routes` to disable Active Storage routes. + + *Gannon McGibbon* + * Image analysis is skipped if ImageMagick returns an error. `ActiveStorage::Analyzer::ImageAnalyzer#metadata` would previously raise a diff --git a/activestorage/config/routes.rb b/activestorage/config/routes.rb index 3af7361cffa7ad7c21aa33fa5193b0829fa13a97..bde53e72f3abfc7a392674bdb79165b92043ca33 100644 --- a/activestorage/config/routes.rb +++ b/activestorage/config/routes.rb @@ -29,4 +29,4 @@ resolve("ActiveStorage::Blob") { |blob, options| route_for(:rails_blob, blob, options) } resolve("ActiveStorage::Attachment") { |attachment, options| route_for(:rails_blob, attachment.blob, options) } -end +end if ActiveStorage.draw_routes diff --git a/activestorage/lib/active_storage.rb b/activestorage/lib/active_storage.rb index 75eb63f0b404452ab31d836bd8c6de81ef512b8b..c35a9920d6e9e28387642bb9052c484d72b38afe 100644 --- a/activestorage/lib/active_storage.rb +++ b/activestorage/lib/active_storage.rb @@ -60,6 +60,7 @@ module ActiveStorage mattr_accessor :service_urls_expire_in, default: 5.minutes mattr_accessor :routes_prefix, default: "/rails/active_storage" + mattr_accessor :draw_routes, default: true mattr_accessor :replace_on_assign_to_many, default: false diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index e88e7fa14e9fc3d9bbcf404d318c53250c58d4a3..9d9cd02d126ab261c3a374c2e36c0bab29bda682 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -73,6 +73,7 @@ class Engine < Rails::Engine # :nodoc: ActiveStorage.analyzers = app.config.active_storage.analyzers || [] ActiveStorage.paths = app.config.active_storage.paths || {} ActiveStorage.routes_prefix = app.config.active_storage.routes_prefix || "/rails/active_storage" + ActiveStorage.draw_routes = app.config.active_storage.draw_routes != false ActiveStorage.variable_content_types = app.config.active_storage.variable_content_types || [] ActiveStorage.content_types_to_serve_as_binary = app.config.active_storage.content_types_to_serve_as_binary || [] diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 4e0224b61e2100d8145057800133d3cd7207d072..80cd141de8e321cc307b9cbf2d7c3bb7757022e4 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -885,6 +885,8 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla * `config.active_storage.replace_on_assign_to_many` determines whether assigning to a collection of attachments declared with `has_many_attached` replaces any existing attachments or appends to them. The default is `true`. +* `config.active_storage.draw_routes` can be used to toggle Active Storage route generation. The default is `true`. + ### Results of `load_defaults` #### With '5.0': diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index a05d86f738502690089396b4d6313aac7d6016d0..96678c395c728e819e160974878d7006599dc041 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -2593,6 +2593,21 @@ class MyLogger < ::Logger MESSAGE end + test "ActiveStorage.draw_routes can be configured via config.active_storage.draw_routes" do + app_file "config/environments/development.rb", <<-RUBY + Rails.application.configure do + config.active_storage.draw_routes = false + end + RUBY + + output = rails("routes") + assert_not_includes(output, "rails_service_blob") + assert_not_includes(output, "rails_blob_representation") + assert_not_includes(output, "rails_disk_service") + assert_not_includes(output, "update_rails_disk_service") + assert_not_includes(output, "rails_direct_uploads") + end + test "hosts include .localhost in development" do app "development" assert_includes Rails.application.config.hosts, ".localhost"