Last active
December 11, 2015 02:48
-
-
Save knutov/4533244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://blogs.perl.org/users/joel_berger/2013/01/a-quick-static-file-webserver.html | |
# alias pws="plackup -MPlack::App::File -e 'Plack::App::File->new->to_app'" | |
# theory: directory requests (by that i assume directory indexes) would work if you s/File/Directory/g :) | |
#!/usr/bin/env perl | |
package Plack::App::IndexFile; | |
use parent 'Plack::App::File'; | |
sub locate_file | |
{ | |
my ($self, $env) = @_; | |
my $path = $env->{PATH_INFO} || ''; | |
return $self->SUPER::locate_file( $env ) unless $path && $path =~ m{/$}; | |
$env->{PATH_INFO} .= 'index.html'; | |
return $self->SUPER::locate_file( $env ); | |
} | |
package main; | |
use Plack::Runner; | |
my $app = Plack::App::IndexFile->new({ root => shift })->to_app; | |
my $runner = Plack::Runner->new; | |
$runner->parse_options( '--access-log' => '/dev/null', @ARGV ); | |
$runner->run( $app ); | |
#----- | |
__END__ | |
pws () { | |
plackup -MPlack::App::File -e ' | |
package PWS; | |
use parent "Plack::App::File"; | |
sub locate_file { | |
$_[1]->{PATH_INFO} .= "index.html" | |
if $_[1]->{PATH_INFO} =~ m{/$}; | |
$_[0]->SUPER::locate_file($_[1]); | |
} | |
PWS->new->to_app; | |
' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment