Open miyagawa opened 14 years ago
More fun with regex. The following seems to serve a static directory (URI) as directory/index.html, where directory is defined as call without "."
enable "Plack::Middleware::Static",
path => sub { s!(^/blog(?:/[^.]*)?/?+$)!${1}/index.html! },
root => '/var/www/static/site/';
enable "Plack::Middleware::Static",
path => qr{^/blog/.+},
root => '/var/www/static/site/';
We'd love to solve this by writing a piece of middleware that wraps ::File (or ::Directory) so that we can actually make it work with non file based backend as well, but haven't figured out how to do so effectively.
https://metacpan.org/release/LLAP/Plack-Middleware-DirIndex-0.01 <- this exists, doesn't try to do anything clever other than add the dir_index if the PATH_INFO ends in /
Patches for smarter stuff welcome, but scratches my itch for now.
DirIndex is working for me, and there are no recent comments --- can this be closed?
From Larry Marso -
Is it possible to coax any of Plack's static modules to automatically serve the index.html a directory level, when a browser is called on that directory?
In other words, how can I get a call to http://site/static/blog to serve up http://site/static/blog/index.html ???
Standard Plack::App::File (or Directory) and Plack::Middleware::Static don't seem to do that.
Best I could come up with was the following hack, which only works for one specified directory. Is there a solution of general applicability?
my $app3 = Plack::App::File->new( file => "/var/www/static/site/blog/index.html")->to_app; builder { enable "Plack::Middleware::Static", path => qr{^/blog/.+}, root => '/var/www/static/site/'; mount "/blog" => $app3; } }
and so on.