class Ki::Middleware::InitMiddleware

Public Instance Methods

call(env) click to toggle source
# File lib/ki/middleware/init_middleware.rb, line 8
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