Class: Indexer::WebUI::Server::IndexHTML

Inherits:
Object
  • Object
show all
Defined in:
lib/indexer/webui.rb

Overview

Rack middleware to serve index.html file by default.

Instance Method Summary collapse

Constructor Details

#initialize(app, root) ⇒ IndexHTML

Returns a new instance of IndexHTML.



135
136
137
138
# File 'lib/indexer/webui.rb', line 135

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

Instance Method Details

#call(env) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/indexer/webui.rb', line 140

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