Class: Madness::TryStatic
- Inherits:
-
Object
- Object
- Madness::TryStatic
- Defined in:
- lib/madness/try_static.rb
Overview
This class allows multiple public folders so that we can load our CSS from the gem-domain public folder, and other things from the user-domain public folder
TryStatic is borrowed from rack-contrib, since the gem is out of date and does not work with Sinatra 2
It is used in ‘server_base.rb` like so:
use TryStatic, :root => "#{config.path}/public/", :urls => %w[/]
Ref:
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ TryStatic
constructor
A new instance of TryStatic.
Constructor Details
#initialize(app, options) ⇒ TryStatic
Returns a new instance of TryStatic.
19 20 21 22 23 24 25 26 27 |
# File 'lib/madness/try_static.rb', line 19 def initialize(app, ) @app = app @try = ['', *[:try]] # :nocov: @static = ::Rack::Static.new( lambda { |_| [404, {}, []] }, ) # :nocov: end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/madness/try_static.rb', line 29 def call(env) orig_path = env['PATH_INFO'] found = nil @try.each do |path| resp = @static.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 |