Add config.api_only option to application and remove appropriate middleware when true
This commit is contained in:
parent
2d86b6d9ae
commit
135c059d6f
@ -13,7 +13,7 @@ class Configuration < ::Rails::Engine::Configuration
|
||||
:railties_order, :relative_url_root, :secret_key_base, :secret_token,
|
||||
:serve_static_files, :ssl_options, :static_cache_control, :static_index,
|
||||
:session_options, :time_zone, :reload_classes_only_on_change,
|
||||
:beginning_of_week, :filter_redirect, :x
|
||||
:beginning_of_week, :filter_redirect, :api_only, :x
|
||||
|
||||
attr_writer :log_level
|
||||
attr_reader :encoding
|
||||
@ -49,6 +49,7 @@ def initialize(*)
|
||||
@eager_load = nil
|
||||
@secret_token = nil
|
||||
@secret_key_base = nil
|
||||
@api_only = false
|
||||
@x = Custom.new
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ def build_stack
|
||||
|
||||
middleware.use ::Rack::Lock unless allow_concurrency?
|
||||
middleware.use ::Rack::Runtime
|
||||
middleware.use ::Rack::MethodOverride
|
||||
middleware.use ::Rack::MethodOverride unless config.api_only
|
||||
middleware.use ::ActionDispatch::RequestId
|
||||
|
||||
# Must come after Rack::MethodOverride to properly log overridden methods
|
||||
@ -42,9 +42,9 @@ def build_stack
|
||||
end
|
||||
|
||||
middleware.use ::ActionDispatch::Callbacks
|
||||
middleware.use ::ActionDispatch::Cookies
|
||||
middleware.use ::ActionDispatch::Cookies unless config.api_only
|
||||
|
||||
if config.session_store
|
||||
if !config.api_only && config.session_store
|
||||
if config.force_ssl && !config.session_options.key?(:secure)
|
||||
config.session_options[:secure] = true
|
||||
end
|
||||
|
@ -50,6 +50,33 @@ def app
|
||||
], middleware
|
||||
end
|
||||
|
||||
test "api middleware stack" do
|
||||
add_to_config "config.api_only = true"
|
||||
|
||||
boot!
|
||||
|
||||
assert_equal [
|
||||
"Rack::Sendfile",
|
||||
"ActionDispatch::Static",
|
||||
"Rack::Lock",
|
||||
"ActiveSupport::Cache::Strategy::LocalCache",
|
||||
"Rack::Runtime",
|
||||
"ActionDispatch::RequestId",
|
||||
"Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods
|
||||
"ActionDispatch::ShowExceptions",
|
||||
"ActionDispatch::DebugExceptions",
|
||||
"ActionDispatch::RemoteIp",
|
||||
"ActionDispatch::Reloader",
|
||||
"ActionDispatch::Callbacks",
|
||||
"ActiveRecord::ConnectionAdapters::ConnectionManagement",
|
||||
"ActiveRecord::QueryCache",
|
||||
"ActionDispatch::ParamsParser",
|
||||
"Rack::Head",
|
||||
"Rack::ConditionalGet",
|
||||
"Rack::ETag"
|
||||
], middleware
|
||||
end
|
||||
|
||||
test "Rack::Cache is not included by default" do
|
||||
boot!
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user