aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorEliot Sykes <eliotsykes@gmail.com>2015-05-04 20:55:23 +0100
committerEliot Sykes <eliotsykes@gmail.com>2015-05-28 09:41:00 +0100
commit3ff39494cdea67502dbd6465358eca3e14a84d6b (patch)
tree89e83c974e2e515de9aa12fcc09176255fa905ee /actionpack/lib
parent7cc9754209c0ae00d70bdd629fa4a81a1c74cc6f (diff)
downloadrails-3ff39494cdea67502dbd6465358eca3e14a84d6b.tar.gz
rails-3ff39494cdea67502dbd6465358eca3e14a84d6b.tar.bz2
rails-3ff39494cdea67502dbd6465358eca3e14a84d6b.zip
config.static_index configures directory index "index.html" filename
Set `config.static_index` to serve a static directory index file not named `index`. For example, to serve `main.html` instead of `index.html` for directory requests, set `config.static_index` to `"main"`.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/middleware/static.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb
index bc5ef1abc9..f20f6ca865 100644
--- a/actionpack/lib/action_dispatch/middleware/static.rb
+++ b/actionpack/lib/action_dispatch/middleware/static.rb
@@ -13,11 +13,12 @@ module ActionDispatch
# located at `public/assets/application.js` if the file exists. If the file
# does not exist, a 404 "File not Found" response will be returned.
class FileHandler
- def initialize(root, cache_control)
+ def initialize(root, cache_control, index)
@root = root.chomp('/')
@compiled_root = /^#{Regexp.escape(root)}/
headers = cache_control && { 'Cache-Control' => cache_control }
@file_server = ::Rack::File.new(@root, headers)
+ @index = index
end
@@ -32,7 +33,7 @@ module ActionDispatch
return false unless path.valid_encoding?
path = Rack::Utils.clean_path_info path
- paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"]
+ paths = [path, "#{path}#{ext}", "#{path}/#{@index}#{ext}"]
if match = paths.detect { |p|
path = File.join(@root, p.force_encoding('UTF-8'))
@@ -104,9 +105,9 @@ module ActionDispatch
# produce a directory traversal using this middleware. Only 'GET' and 'HEAD'
# requests will result in a file being returned.
class Static
- def initialize(app, path, cache_control=nil)
+ def initialize(app, path, cache_control=nil, index="index")
@app = app
- @file_handler = FileHandler.new(path, cache_control)
+ @file_handler = FileHandler.new(path, cache_control, index)
end
def call(env)