Class: Rack::DirectoryIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/directory_index.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DirectoryIndex

Returns a new instance of DirectoryIndex.



3
4
5
# File 'lib/rack/directory_index.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rack/directory_index.rb', line 6

def call(env)
  index_path = ::File.join(Rails.root, 'public', Rack::Request.new(env).path.split('/'), 'index.html')
  
  p index_path
  
  if ::File.exists?(index_path)
    return [200, {"Content-Type" => "text/html"}, ::File.read(index_path)]
  else
    @app.call(env)
  end
end