Class: Brite::Server::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/brite/server.rb

Overview

Rack middleware to serve ‘index.html` file by default.

Instance Method Summary collapse

Constructor Details

#initialize(app, root) ⇒ Index

Returns a new instance of Index.



108
109
110
111
# File 'lib/brite/server.rb', line 108

def initialize(app, root)
  @app  = app
  @root = root || Dir.pwd
end

Instance Method Details

#call(env) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/brite/server.rb', line 113

def call(env)
  path = Rack::Utils.unescape(env['PATH_INFO'])
  index_file = File.join(@root, path, 'index.html')
  if File.exists?(index_file)
    [200, {'Content-Type' => 'text/html'}, File.new(index_file)]
  else
    @app.call(env) #Rack::Directory.new(@root).call(env)
  end
end