Class: Ki::Middleware::InitMiddleware

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

Instance Method Summary collapse

Methods included from BaseMiddleware

#initialize

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ki/middleware/init_middleware.rb', line 6

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