-
-
30 Nov 2020 00:21:36 UTC
- Distribution: Plack
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (98)
- Testers (4634 / 10 / 0)
- Kwalitee
Bus factor: 1- 80.40% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity
24 month- Tools
- Download (185.98KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 131 contributors- Tatsuhiko Miyagawa
-
Aaron Trevena
-
Ævar Arnfjörð Bjarmason
-
Akzhan Abdulin
-
Alexandr Ciornii
-
Alex J. G. Burzyński
-
Allan Whiteford
-
Andrew Fresh
-
Andrew Rodland
-
Andy Wardley
-
Aristotle Pagaltzis
-
Arthur Axel 'fREW' Schmidt
-
Asato Wakisaka
-
Ashley Pond V
-
Ask Bjørn Hansen
-
ben hengst
-
Ben Morrow
-
Bernhard Graf
-
Chad Granum
-
chansen
-
Chia-liang Kao
-
cho45
-
Christian Walde
-
chromatic
-
Cosimo Streppone
-
Dagfinn Ilmari Mannsåker
-
Daisuke Maki
-
Daisuke Murase
-
Dave Marr
-
Dave Rolsky
-
David E. Wheeler
-
David Schmidt
-
David Steinbrunner
-
dmaestro
-
Eduardo Arino de la Rubia
-
Emmanuel Seyman
-
Eric Johnson
-
Eugen Konkov
-
Fabrice Gabolde
-
fayland
-
Flavio Poletti
-
Florian Ragwitz
-
franck cuny
-
Gianni Ceccarelli
-
Graham Knop
-
Grant McLean
-
Hans Dieter Pearcey
-
Haruka Iwao
-
Henry Baragar
-
hiratara
-
HIROSE Masaaki
-
Hiroshi Sakai
-
Ian Bradley
-
Ian Burrell
-
Jakob Voss
-
Jay Hannah
-
Jesse Luehrs
-
Jiro Nishiguchi
-
Johannes Plunien
-
John Beppu
-
John Napiorkowski
-
Jonathan Swartz
-
José Pinheiro Neta
-
Justin Davis
-
kakuno
-
Kang-min Liu
-
Karen Etheridge
-
Kazuho Oku
-
Keedi Kim
-
Lee Aylward
-
Leo Lapworth
-
mala
-
Marco Pessotto
-
Marian Schubert
-
Mark Fowler
-
Mark Stosberg
-
Masahiro Chiba
-
Masahiro Nagano
-
Michael G. Schwern
-
Michal Josef Špaček
-
mickey
-
Narsimham Chelluri
-
Nick Wellnhofer
-
Nobuo Danjou
-
Olaf Alders
-
Oliver Gorwits
-
Oliver Paukstadt
-
Oliver Trosien
-
Olivier Mengué
-
osfameron
-
Panu Ervamaa
-
Paul Driver
-
Pedro Melo
-
Perlover
-
Peter Flanigan
-
Peter Makholm
-
Piotr Roszatycki
-
punytan
-
Rafael Kitover
-
Randy Stauner
-
Ray Miller
-
Richard Simões
-
Ricky Morse
-
Robert Rothenberg
-
Rob Hoelz
-
runarb
-
Ryo Miyake
-
Sawyer X
-
Scott S. McCoy
-
Shawn M Moore
-
Shoichi Kaji
-
smcmurray
-
Stephen Clouse
-
Stevan Little
-
Stuart A Johnston
-
Takeshi OKURA
-
The Dumb Terminal
-
Thomas Klausner
-
Thomas Sibley
-
Tim Bunce
-
Tokuhiro Matsuno
-
Tomas Doran
-
Tom Heady
-
vti
-
Wallace Reis
-
xaicron
-
Yann Kerherve
-
yappo
-
Yury Zavarin
-
Yuval Kogman
-
唐鳳
- Dependencies
- Apache::LogFormat::Compiler
- Cookie::Baker
- Devel::StackTrace
- Devel::StackTrace::AsHTML
- File::ShareDir
- Filesys::Notify::Simple
- HTTP::Entity::Parser
- HTTP::Headers::Fast
- HTTP::Message
- HTTP::Tiny
- Hash::MultiValue
- Pod::Usage
- Stream::Buffered
- Test::TCP
- Try::Tiny
- URI
- WWW::Form::UrlEncoded
- parent
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Plack::Middleware::Static - serve static files with Plack
SYNOPSIS
use Plack::Builder; builder { enable "Plack::Middleware::Static", path => qr{^/(images|js|css)/}, root => './htdocs/'; $app; };
DESCRIPTION
This middleware allows your Plack-based application to serve static files.
Note that if you are building an app using Plack::App::URLMap, you should consider using Plack::App::File to serve static files instead. This makes the overall routing of your application simpler to understand.
With this middleware, if a static file exists for the requested path, it will be served. If it does not exist, by default this middleware returns a 404, but you can set the
pass_through
option to change this behavior.If the requested document is not within the
root
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 by using Plack::MIME or using
content_type
.CONFIGURATIONS
- 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 inroot
to find the static files to serve. The default value ofroot
is the current directory.This example configuration serves
/static/foo.jpg
fromhtdocs/static/foo.jpg
. Note that the matched portion of the path,/static/
, still appears in the locally mapped path underroot
. 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 theroot
.The configuration above serves
/static/foo.png
fromstatic-files/foo.png
, notstatic-files/static/foo.png
. The callback specified in thepath
option matches against$_
munges this value usings///
. 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.
AUTHOR
Tokuhiro Matsuno, Tatsuhiko Miyagawa
SEE ALSO
Module Install Instructions
To install Plack, copy and paste the appropriate command in to your terminal.
cpanm Plack
perl -MCPAN -e shell install Plack
For more information on module installation, please visit the detailed CPAN module installation guide.