1Plack::Middleware::StatUisce(r3)Contributed Perl DocumenPtlaatciko:n:Middleware::Static(3)
2
3
4

NAME

6       Plack::Middleware::Static - serve static files with Plack
7

SYNOPSIS

9         use Plack::Builder;
10
11         builder {
12             enable "Plack::Middleware::Static",
13                 path => qr{^/(images|js|css)/}, root => './htdocs/';
14             $app;
15         };
16

DESCRIPTION

18       Enable this middleware to allow your Plack-based application to serve
19       static files.
20
21       If the given request matches with the pattern defined in "path", this
22       middleware will try to locate the file in "root". If the file exists it
23       will be served but otherwise 404 response will be returned. See
24       "pass_through" option below to change this behavior.
25
26       If the requested document is not within the "root" (i.e. directory
27       traversal) or the file is there but not readable, a 403 Forbidden
28       response will be returned.
29
30       The content type returned will be determined from the file extension
31       based on Plack::MIME.
32

CONFIGURATIONS

34       path, root
35             enable "Plack::Middleware::Static",
36                 path => qr{^/static/}, root => 'htdocs/';
37
38           "path" specifies the URL pattern (regular expression) or a callback
39           to match with requests to serve static files for. "root" specifies
40           the root directory to serve those static files from. The default
41           value of "root" is the current directory.
42
43           This examples configuration serves "/static/foo.jpg" from
44           "htdocs/static/foo.jpg". Note that the matched "/static/" portion
45           is still appears in the local mapped path. If you don't like it,
46           use a callback instead to munge $_:
47
48             enable "Plack::Middleware::Static",
49                 path => sub { s!^/static/!! }, root => 'static-files/';
50
51           This configuration would serve "/static/foo.png" from
52           "static-files/foo.png" (not "static-files/static/foo.png"). The
53           callback specified in "path" option matches against $_ and then
54           updates the value since it does s///, and returns the number of
55           matches, so it will pass through when "/static/" doesn't match.
56
57           If you want to map multiple static directories from different root,
58           simply add "this", middleware multiple times with different
59           configuration options.
60
61       pass_through
62           By turning on this option, this middleware will pass the request
63           back to the application for further processing, if the incoming
64           request path matches with the "path" but the requested file is not
65           found on the file system.
66

AUTHOR

68       Tokuhiro Matsuno, Tatsuhiko Miyagawa
69

SEE ALSO

71       Plack::Middleware Plack::Builder
72
73
74
75perl v5.12.3                      2011-06-22      Plack::Middleware::Static(3)
Impressum