Sha256: 6878a1351208cc17d612900ba3408ed3e9bc2b5309a7d9671456d110d3f2a785

Contents?: true

Size: 568 Bytes

Versions: 2

Compression:

Stored size: 568 Bytes

Contents

module Swagui
  class AssetHandler

    def initialize(path)
      @url_regex = Regexp.union(Regexp.new("^\/swagger-ui"), Regexp.new("^#{path}\/?$"))
      swagger_ui_dir = File.expand_path('../../swagger-ui', File.dirname(__FILE__))
      @asset_file_server = Rack::File.new(swagger_ui_dir)
    end

    def handles?(env)
      @url_regex === env["PATH_INFO"]
    end

    def call(env)
      env["PATH_INFO"] = env["PATH_INFO"].gsub(@url_regex, '')
      env["PATH_INFO"] = 'index.html' if env["PATH_INFO"] == ''
      @asset_file_server.call(env)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
swagui-0.1.2 lib/swagui/asset_handler.rb
swagui-0.1.1 lib/swagui/asset_handler.rb