Serving a static site (the content of a directory) using Plack and PSGI

plackup Plack::Builder Plack::App::File Plack::Middleware::DirIndex

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'

Other pages

Testing PSGI based web applications using Plack::Test
PSGI the superglue between Perl web application frameworks and web servers

Author

Gabor Szabo (szabgab) Gabor Szabo