»  Home · About · Posts by Topic

How to serve a static directory with Plack

Feb 13, 2011 ·  From directory to http://localhost:5001/page.html as simply as possible.

You have a directory containing HTML files and would like to browse it locally. There are absolute links like /static/site.css in the HTML, so just opening index.html would break those links.

Perl’s recent web superstar module Plack can do it easily.

Create a file named plack.psgi with the following content:

#!/usr/bin/env perl

use Plack::App::File;

my $root = "/path/to/dir;
my $app = Plack::App::File->new(root => $root)->to_app;

Then launch the plackup utility by plackup -a plack.psgi --port 5001--that’s it!