3 # The Rack::Static middleware intercepts requests for static files
4 # (javascript files, images, stylesheets, etc) based on the url prefixes
5 # passed in the options, and serves them using a Rack::File object. This
6 # allows a Rack stack to serve both static and dynamic content.
9 # use Rack::Static, :urls => ["/media"]
10 # will serve all requests beginning with /media from the "media" folder
11 # located in the current directory (ie media/*).
13 # use Rack::Static, :urls => ["/css", "/images"], :root => "public"
14 # will serve all requests beginning with /css or /images from the folder
15 # "public" in the current directory (ie public/css/* and public/images/*)
19 def initialize(app
, options
={})
21 @urls = options
[:urls] || ["/favicon.ico"]
22 root
= options
[:root] || Dir
.pwd
23 @file_server = Rack
::File.new(root
)
27 path
= env["PATH_INFO"]
28 can_serve
= @urls.any
? { |url
| path
.index(url
) == 0 }
31 @file_server.call(env)