mirror of
https://github.com/danog/sass-site.git
synced 2024-11-27 12:35:03 +01:00
18 lines
481 B
Ruby
18 lines
481 B
Ruby
# Like Rack::TryStatic, but tries each possible URL with the app instead.
|
|
class Rack::TryDynamic
|
|
def initialize(app, options)
|
|
@app = app
|
|
@try = ['', *options[:try]]
|
|
end
|
|
|
|
def call(env)
|
|
orig_path = env['PATH_INFO']
|
|
found = nil
|
|
@try.each do |path|
|
|
resp = @app.call(env.merge!({'PATH_INFO' => orig_path + path}))
|
|
break if !(403..405).include?(resp[0]) && found = resp
|
|
end
|
|
found or @app.call(env.merge!('PATH_INFO' => orig_path))
|
|
end
|
|
end
|