Rechercher une page de manuel
Plack::Middleware::Static.3pm
Langue: en
Version: 2010-03-30 (ubuntu - 24/10/10)
Section: 3 (Bibliothèques de fonctions)
NAME
Plack::Middleware::Static - serve static files with PlackSYNOPSIS
use Plack::Builder; builder { enable "Plack::Middleware::Static", path => qr{^/(images|js|css)/}, root => './htdocs/'; $app; };
DESCRIPTION
Enable this middleware to allow your Plack-based application to serve static files. If a static file exists for the requested path, it will be served. Otherwise, the request will be passed on to the application for further processing.If the requested document is not within the "root" (i.e. directory traversal) or the file is there but not readable, this middleware will return a 403 Forbidden response.
The content type returned will be determined from the file extension based on Plack::MIME.
CONFIGURATIONS
- path, root
-
enable "Plack::Middleware::Static", path => qr{^/static/}, root => 'htdocs/';
"path" specifies the URL pattern (regular expression) or a callback to match with requests to serve static files for. "root" specifies the root directory to serve those static files from. The default value of "root" is the current directory.
This examples configuration serves "/static/foo.jpg" from "htdocs/static/foo.jpg". Note that the matched "/static/" portion is still appears in the local mapped path. If you don't like it, use a callback instead to munge $_:
enable "Plack::Middleware::Static", path => sub { s!^/static/!! }, root => 'static-files/';
This configuration would serve "/static/foo.png" from "static-files/foo.png" (not "static-files/static/foo.png"). The callback specified in "path" option matches against $_ and then updates the value since it does s///, and returns the number of matches, so it will pass through when "/static/" doesn't match.
If you want to map multiple static directories from different root, simply add ``this'', middleware multiple times with different configuration options.
AUTHOR
Tokuhiro Matsuno, Tatsuhiko MiyagawaSEE ALSO
Plack::Middleware Plack::BuilderContenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre