The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojolicious::Plugin::Directory - Serve static files from document root with directory index

SYNOPSIS

# simple usage
use Mojolicious::Lite;
plugin( 'Directory', root => "/path/to/htdocs" )->start;

# with handler
use Text::Markdown qw{ markdown };
use Path::Class;
use Encode qw{ decode_utf8 };
plugin('Directory', root => "/path/to/htdocs", handler => sub {
    my ($c, $path) = @_;
    if ($path =~ /\.(md|mkdn)$/) {
        my $text = file($path)->slurp;
        my $html = markdown( decode_utf8($text) );
        $c->render( inline => $html );
    }
})->start;

or

> perl -Mojo -E 'a->plugin("Directory", root => "/path/to/htdocs")->start' daemon

DESCRIPTION

Mojolicious::Plugin::Directory is a static file server directory index a la Apache's mod_autoindex.

CONFIGURATION

root
Document root directory. Defaults to the current directory.

if root is a file, serve only root file.
dir_page
a HTML template of index page
handler
CODE BLOCK for handle a request file.

if not rendered in CODE BLOCK, serve as static file.

AUTHOR

hayajo <hayajo@cpan.org>

SEE ALSO

Plack::App::Directory

LICENSE

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