class Yarrow::Server::DirectoryIndex

Rack Middleware for detecting and serving an ‘index.html’ file instead of a directory index.

TODO: Fix bug where a directory /index.html/ causes this to crash TODO: Add configurable mapping and media types for README files as an alternative

Public Class Methods

new(app, options={}) click to toggle source
# File lib/yarrow/server.rb, line 29
def initialize(app, options={})
  @app = app
  @root = options[:root]
  @index_file = options[:index]
end

Public Instance Methods

call(env) click to toggle source
# File lib/yarrow/server.rb, line 35
def call(env)
  index_path = File.join(@root, Rack::Request.new(env).path.split('/'), @index_file)
  if File.exist?(index_path)
    return [200, {"Content-Type" => "text/html"}, [File.read(index_path)]]
  else
    @app.call(env)
  end
end