Class: Phaedra::Middleware::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/phaedra/rack_middleware/static.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ Static

Returns a new instance of Static.



7
8
9
10
11
12
13
# File 'lib/phaedra/rack_middleware/static.rb', line 7

def initialize(app, options)
  @app = app
  @try = ["", ".html", "index.html", "/index.html", *options[:try]]
  @static = Rack::Static.new(
    lambda { |_| [404, {}, []] },
    options)
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/phaedra/rack_middleware/static.rb', line 15

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