Created
April 14, 2010 11:06
-
-
Save hokaccha/365684 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Getopt::Long; | |
use Pod::Usage; | |
use File::Which qw/which/; | |
use File::Temp; | |
use Path::Class qw/dir/; | |
my $root = '.'; | |
my $port = 5050; | |
my $help; | |
GetOptions ( | |
'root|r=s' => \$root, | |
'port|p=i' => \$port, | |
'help|h' => \$help, | |
); | |
pod2usage() if $help; | |
my $root_dir = dir($root)->absolute->stringify; | |
print "document root: $root_dir\n"; | |
my $app_psgi = <<'...'; | |
use Plack::Middleware::Static; | |
sub { | |
$env = shift; | |
if ($env->{PATH_INFO} =~ m!/$!) { | |
$env->{PATH_INFO} .= 'index.html'; | |
} | |
$app = Plack::Middleware::Static->new({ | |
path => sub { 1 }, | |
root => '%s' | |
}); | |
$app->call($env); | |
}; | |
... | |
my $fh = File::Temp->new; | |
print $fh sprintf($app_psgi, $root_dir); | |
my $plackup = which('plackup') or die 'require plackup command'; | |
system($plackup, '-a', $fh->filename, '-p', $port, '-s', 'Standalone::Prefork'); | |
__END__ | |
=head1 SYNOPSIS | |
$ static_server [-p port] [-r root] [-h] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment