NAME

Plack::App::DirectoryIndex - Serve static files from document root with an index file.

SYNOPSIS

# app.psgi
use Plack::App::DirectoryIndex;

# Use the default index file (index.html)
my $app = Plack::App::DirectoryIndex->new({
  root => '/path/to/htdocs',
})->to_app;

# Use a different index file
my $app = Plack::App::DirectoryIndex->new({
  root      => '/path/to/htdocs',
  dir_index => 'default.html',
})->to_app;

# Don't use an index file (but you're probably better
# off just using Plack::App::Directory instead)
my $app = Plack::App::DirectoryIndex->new({
  root      => '/path/to/htdocs',
  dir_index => '',
})->to_app;

DESCRIPTION

This is a static file server PSGI application with directory index like Apache's mod_autoindex. Unlike Plack::App::Directory, it will also look for a default index file (e.g. index.html) and serve that instead of a directory listing.

CONFIGURATION

root

Document root directory. Defaults to the current directory.

dir_index

The name of the directory index file that you want to use. This will default to using index.html. You can turn it off by setting this value to an empty string (but if you don't want a default index file, then you should probably use Plack::App::Directory instead).

AUTHOR

Dave Cross <dave@perlhacks.com>

COPYRIGHT

Copyright (c) 2020 Magnum Solutions Limited. All rights reserved.

LICENCE

This code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Plack::App::File

A Plack application for serving static files from a directory. This app only returns files. If you request a directory, you will get a 404 error.

Plack::App::Directory

Another Plack application for serving static files from a directory. This app will serve a directory listing if you request one, but it doesn't support default directory index files like index.html.

Plack::Middleware::DirIndex

This is Plack middleware that it intended to add support for a default directory index file to an existing Plack application. Unfortunately, it is an all-or-nothing solution. If you use this middleware, then whenever you request a directory, it will add the directory index filename to the end of the request path. If your directory doesn't contain a file with the correct name (ususally index.html), then it will return a 404 error.