Class: Ki::Middleware::InitMiddleware

Inherits:
Object
  • Object
show all
Includes:
BaseMiddleware
Defined in:
lib/ki/middleware.rb

Instance Method Summary collapse

Methods included from BaseMiddleware

#initialize

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ki/middleware.rb', line 29

def call env
  req = BaseRequest.new env
  if req.root?
    if public_file_exists? 'index.html'
      env['PATH_INFO'] = '/index.html'
      Rack::File.new(Ki::PUBLIC_PATH).call env
    else
      resp = Rack::Response.new
      resp.redirect('/index')
      resp.finish
    end
  else
    env['CONTENT_TYPE'] = 'application/json' if format_of(req) == 'json'
    @app.call env
  end
end