Class: Openapi::Rswag::Ui::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Middleware

Returns a new instance of Middleware.



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

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

Instance Method Details

#call(env) ⇒ Object



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

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