Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enable static asset server by default

  • Loading branch information...
commit dbb32115ef45dd58667e450125deba80d7016341 1 parent 79a4d50
@josh josh authored
View
1  railties/lib/rails/commands/server.rb
@@ -57,7 +57,6 @@
app = Rack::Builder.new {
use Rails::Rack::LogTailer unless options[:detach]
use Rails::Rack::Debugger if options[:debugger]
- use Rails::Rack::Static
run ActionDispatch::Utils.parse_config(options[:config])
}.to_app
View
7 railties/lib/rails/configuration.rb
@@ -10,7 +10,7 @@ class Configuration
:log_path, :log_level, :logger, :preload_frameworks,
:database_configuration_file, :cache_store, :time_zone,
:view_path, :metals, :controller_paths, :routes_configuration_file,
- :eager_load_paths, :dependency_loading, :paths
+ :eager_load_paths, :dependency_loading, :paths, :serve_static_assets
def initialize
set_root_path!
@@ -35,6 +35,7 @@ def initialize
@controller_paths = default_controller_paths
@routes_configuration_file = default_routes_configuration_file
@database_configuration_file = default_database_configuration_file
+ @serve_static_assets = default_serve_static_assets
for framework in default_frameworks
self.send("#{framework}=", Rails::OrderedOptions.new)
@@ -225,6 +226,10 @@ def default_i18n
i18n
end
+ def default_serve_static_assets
+ true
+ end
+
# Adds a single Gem dependency to the rails application. By default, it will require
# the library with the same name as the gem. Use :lib to specify a different name.
#
View
6 railties/lib/rails/generators/rails/app/templates/config/environments/production.rb
@@ -17,6 +17,10 @@
# Use a different cache store in production
# config.cache_store = :mem_cache_store
+# Disable Rails's static asset server
+# In production, Apache or nginx will already do this
+config.serve_static_assets = false
+
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
@@ -24,4 +28,4 @@
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
-# config.threadsafe!
+# config.threadsafe!
View
7 railties/lib/rails/initializer.rb
@@ -269,6 +269,13 @@ def self.run(initializer = nil, config = nil)
end
end
+ # Include middleware to serve up static assets
+ Initializer.default.add :initialize_static_server do
+ if configuration.frameworks.include?(:action_controller) && configuration.serve_static_assets
+ configuration.middleware.insert(0, Rails::Rack::Static, Rails.public_path)
+ end
+ end
+
Initializer.default.add :initialize_cache do
unless defined?(RAILS_CACHE)
silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }
View
4 railties/lib/rails/rack/static.rb
@@ -5,9 +5,9 @@ module Rack
class Static
FILE_METHODS = %w(GET HEAD).freeze
- def initialize(app)
+ def initialize(app, root)
@app = app
- @file_server = ::Rack::File.new(File.join(RAILS_ROOT, "public"))
+ @file_server = ::Rack::File.new(root)
end
def call(env)
View
1  railties/test/application/load_test.rb
@@ -17,7 +17,6 @@ def setup
test "running Rails::Application.load on the path returns a (vaguely) useful application" do
app_file "config.ru", <<-CONFIG
require File.dirname(__FILE__) + '/config/environment'
- use Rails::Rack::Static
run ActionController::Dispatcher.new
CONFIG
View
2  railties/test/rack_static_test.rb
@@ -15,7 +15,7 @@ def teardown
DummyApp = lambda { |env|
[200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
}
- App = Rails::Rack::Static.new(DummyApp)
+ App = Rails::Rack::Static.new(DummyApp, "#{RAILS_ROOT}/public")
test "serves dynamic content" do
assert_equal "Hello, World!", get("/nofile")
Please sign in to comment.
Something went wrong with that request. Please try again.