Serving a static site (the content of a directory) using Plack and PSGI
Just a simple example using Plack::Builder and Plack::App::File to serve some static files using a Perl-based web server.
examples/static_psgi/app.psgi
use strict; use warnings; use Plack::Builder; use Plack::App::File; my $app = Plack::App::File->new(root => "www")->to_app; builder { enable "DirIndex", dir_index => 'index.html'; $app; }
Put this in a directory as app.psgi. Put your HTML files in the 'www' subdirectory. Run plackup and you can visit http://127.0.0.1:5000/ to see the pages.
In this code we use the Plack::Middleware::DirIndex middleware that handles the files in the given directory.
Check out the other articles on Plack/PSGI.
Comments
There is handy oneliner as well: plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root => ".")->to_app'
Published on 2017-05-13