Skip to content

Instantly share code, notes, and snippets.

@book
Last active September 17, 2025 06:30
Show Gist options
  • Save book/bab7b15210576ca227fbc54d066dc1b1 to your computer and use it in GitHub Desktop.
Save book/bab7b15210576ca227fbc54d066dc1b1 to your computer and use it in GitHub Desktop.
Static Plack Web Server
# run from the directory to be served, with:
#
# plackup -s Starman -p 5555 static.psgi
#
use strict;
use warnings;
use Plack::App::Directory;
my $static = Plack::App::Directory->new( { root => shift // '.' } )->to_app;
my $app = sub {
my $env = shift;
my $path = Plack::Request->new($env)->path;
return
substr( $path, -1, 1 ) eq "/"
? [ 301, [ Location => "${path}index.html" ], [] ]
: $static->($env);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment