path, root
enable "Plack::Middleware::Static",
path => qr{^/static/}, root => 'htdocs/';
The "path" option specifies the URL pattern (regular expression) or a callback to match against
requests. If the <path> option matches, the middleware looks in "root" to find the static files to
serve. The default value of "root" is the current directory.
This example configuration serves "/static/foo.jpg" from "htdocs/static/foo.jpg". Note that the
matched portion of the path, "/static/", still appears in the locally mapped path under "root". If
you don't want this to happen, you can use a callback to munge the path as you match it:
enable "Plack::Middleware::Static",
path => sub { s!^/static/!! }, root => 'static-files/';
The callback should operate on $_ and return a true or false value. Any changes it makes to $_ are
used when looking for the static file in the "root".
The configuration above serves "/static/foo.png" from "static-files/foo.png", not
"static-files/static/foo.png". The callback specified in the "path" option matches against $_ munges
this value using "s///". The substitution operator returns the number of matches it made, so it will
return true when the path matches "^/static".
For more complex static handling in the "path" callback, in addition to $_ being set the callback
receives two arguments, "PATH_INFO" (same as $_) and $env.
If you want to map multiple static directories from different roots, simply add this middleware
multiple times with different configuration options.
pass_through
When this option is set to a true value, then this middleware will never return a 404 if it cannot
find a matching file. Instead, it will simply pass the request on to the application it is wrapping.
content_type
The "content_type" option can be used to provide access to a different MIME database than
Plack::MIME. Plack::MIME works fast and good for a list of well known file endings, but if you need
a more accurate content based checking you can use modules like File::MimeInfo or File::MMagic for
example. The callback should work on $_[0] which is the filename of the file.