Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App::File and Directory to support index.html #93

Open
miyagawa opened this issue Mar 22, 2010 · 4 comments
Open

App::File and Directory to support index.html #93

miyagawa opened this issue Mar 22, 2010 · 4 comments
Labels

Comments

@miyagawa
Copy link
Member

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.

@lmarso
Copy link

lmarso commented Mar 22, 2010

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/';

chromatic added a commit to chromatic/Plack that referenced this issue Jun 16, 2011
This allows you to specify a file to return when a request asks for a directory
but no file exists at that path. See GH plack#93.
@miyagawa
Copy link
Member Author

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.

@ranguard
Copy link
Contributor

ranguard commented Jun 3, 2012

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.

@cxw42
Copy link

cxw42 commented Jan 31, 2020

DirIndex is working for me, and there are no recent comments --- can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants