diff options
Diffstat (limited to 'railties/lib/rails/application.rb')
-rw-r--r-- | railties/lib/rails/application.rb | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index a3b3a56bc8..85ae8cbbb1 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -27,7 +27,7 @@ module Rails # Besides providing the same configuration as Rails::Engine and Rails::Railtie, # the application object has several specific configurations, for example # "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters", - # "logger", "metals", "reload_engines", "reload_plugins" and so forth. + # "logger", "reload_engines", "reload_plugins" and so forth. # # Check Rails::Application::Configuration to see them all. # @@ -36,17 +36,15 @@ module Rails # The application object is also responsible for holding the routes and reloading routes # whenever the files change in development. # - # == Middlewares and metals + # == Middlewares # - # The Application is also responsible for building the middleware stack and setting up - # both application and engines metals. + # The Application is also responsible for building the middleware stack. # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' autoload :Configurable, 'rails/application/configurable' autoload :Configuration, 'rails/application/configuration' autoload :Finisher, 'rails/application/finisher' - autoload :MetalLoader, 'rails/application/metal_loader' autoload :Railties, 'rails/application/railties' autoload :RoutesReloader, 'rails/application/routes_reloader' @@ -69,6 +67,7 @@ module Rails raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance + Rails.application.add_lib_to_load_paths! ActiveSupport.run_load_hooks(:before_configuration, base.instance) end @@ -83,13 +82,23 @@ module Rails end end - delegate :middleware, :metal_loader, :to => :config + delegate :middleware, :to => :config + + def add_lib_to_load_paths! + path = config.root.join('lib').to_s + $LOAD_PATH.unshift(path) if File.exists?(path) + end def require_environment! environment = paths.config.environment.to_a.first require environment if environment end + def eager_load! + railties.all(&:eager_load!) + super + end + def routes @routes ||= ActionDispatch::Routing::RouteSet.new end @@ -126,7 +135,10 @@ module Rails end def app - @app ||= config.middleware.build(routes) + @app ||= begin + config.middleware = config.middleware.merge_into(default_middleware_stack) + config.middleware.build(routes) + end end def call(env) @@ -150,6 +162,29 @@ module Rails protected + def default_middleware_stack + ActionDispatch::MiddlewareStack.new.tap do |middleware| + middleware.use ::ActionDispatch::Static, paths.public.to_a.first if config.serve_static_assets + middleware.use ::Rack::Lock if !config.allow_concurrency + middleware.use ::Rack::Runtime + middleware.use ::Rails::Rack::Logger + middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local if config.action_dispatch.show_exceptions + middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies + middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header + middleware.use ::ActionDispatch::Callbacks, !config.cache_classes + middleware.use ::ActionDispatch::Cookies + + if config.session_store + middleware.use config.session_store, config.session_options + middleware.use ::ActionDispatch::Flash + end + + middleware.use ::ActionDispatch::ParamsParser + middleware.use ::Rack::MethodOverride + middleware.use ::ActionDispatch::Head + end + end + def initialize_tasks require "rails/tasks" task :environment do |