Last active
September 17, 2025 06:30
-
-
Save book/bab7b15210576ca227fbc54d066dc1b1 to your computer and use it in GitHub Desktop.
Static Plack Web Server
This file contains hidden or 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
| # 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