Class: Rswag::Ui::Middleware

Inherits:
Rack::Static
  • Object
show all
Defined in:
lib/rswag/ui/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Middleware

Returns a new instance of Middleware.



5
6
7
8
# File 'lib/rswag/ui/middleware.rb', line 5

def initialize(app, config)
  @config = config
  super(app, urls: [ '' ], root: config.assets_root )
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rswag/ui/middleware.rb', line 10

def call(env)
  if base_path?(env)
    redirect_uri = env['SCRIPT_NAME'].chomp('/') + '/index.html'
    return [ 301, { 'Location' => redirect_uri }, [ ] ]
  end

  if index_path?(env)
    return [ 200, { 'Content-Type' => 'text/html' }, [ render_template ] ]
  end

  super
end