Skip to content

Instantly share code, notes, and snippets.

@hdp
Created March 10, 2011 03:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdp/863516 to your computer and use it in GitHub Desktop.
Save hdp/863516 to your computer and use it in GitHub Desktop.
my $root = '.';
my @indexes = qw(index.html);
use strict;
use warnings;
use Plack::App::File;
use Plack::App::Cascade;
sub directory_indexes {
my ($root, @indexes) = @_;
my $file = Plack::App::File->new(root => $root)->to_app;
my $serve_index = sub {
my ($index) = @_;
return sub {
my $env = shift;
my $path = $env->{PATH_INFO};
local $env->{PATH_INFO} = "$path/$index";
return $file->($env);
};
};
my $cascade = Plack::App::Cascade->new;
for my $index (@indexes) {
$cascade->add($serve_index->($index));
}
$cascade->add($file);
return $cascade->to_app;
}
directory_indexes($root, @indexes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment