Class: Utopia::Middleware::DirectoryIndex
- Defined in:
- lib/utopia/middleware/directory_index.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ DirectoryIndex
constructor
A new instance of DirectoryIndex.
Constructor Details
#initialize(app, options = {}) ⇒ DirectoryIndex
Returns a new instance of DirectoryIndex.
28 29 30 31 32 33 34 35 |
# File 'lib/utopia/middleware/directory_index.rb', line 28 def initialize(app, = {}) @app = app @root = [:root] || Utopia::Middleware::default_root @files = ["index.html"] @default = "index" end |
Instance Method Details
#call(env) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/utopia/middleware/directory_index.rb', line 37 def call(env) path = Path.create(env["PATH_INFO"]) if path.directory? # Check to see if one of the files exists in the requested directory @files.each do |file| if File.exist?(File.join(@root, path.components, file)) return [307, {"Location" => (path + file).to_s}, []] end end # Use the default path return [307, {"Location" => (path + @default).to_s}, []] else return @app.call(env) end end |