Class: BridgetownPluginNano::Middleware::Static
- Inherits:
-
Object
- Object
- BridgetownPluginNano::Middleware::Static
- Defined in:
- lib/bridgetown-plugin-nano/rack_middleware/static.rb
Overview
Based on Rack::TryStatic middleware github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ Static
constructor
A new instance of Static.
Constructor Details
#initialize(app, options) ⇒ Static
Returns a new instance of Static.
9 10 11 12 13 14 15 16 |
# File 'lib/bridgetown-plugin-nano/rack_middleware/static.rb', line 9 def initialize(app, ) @app = app @try = ["", ".html", "index.html", "/index.html", *[:try]] @static = Rack::Static.new( ->(_) { [404, {}, []] }, ) end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/bridgetown-plugin-nano/rack_middleware/static.rb', line 18 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).cover?(resp[0]) && (found = resp) end found || @app.call(env.merge!("PATH_INFO" => orig_path)) end |