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


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

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

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

  # 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 => '',


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.



Document root directory. Defaults to the current directory.


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).


Dave Cross <>


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


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



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.


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.


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.