bangor has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a project and using Plack for the first time. I am having a little problem getting my static files served...

Directory structure:
app/test.psgi app/pod-files/test.pod app/static/test.html app/html-files/test.html
The code I have for the builder part in test.psgi is:
builder { enable "Static", path => qr!^/static!, ; enable "Plack::Middleware::Pod", # great module! path => qr!^/pod!, root => 'pod-files', pod_view => 'Pod::POM::View::HTML', ; $app; };
The pod and static files serve up fine:
/app/pod/test.pod OK /app/static/test.html OK
But I want to serve the static files from a different directory to static, so I change the builder to:
builder { enable "Static", path => qr!^/static!, root => 'html-files', ; enable "Plack::Middleware::Pod", path => qr!^/pod!, root => 'pod-files', pod_view => 'Pod::POM::View::HTML', ; $app; };
But, this doesnt work - I now get:
/app/pod/test.pod OK /app/static/test.html not found
I have played around with different values of 'root' but no luck. Any help appreciated.

** Update: managed to work it out - see my comment below

Replies are listed 'Best First'.
Re: Serving static files with Plack
by bangor (Monk) on Apr 20, 2016 at 23:05 UTC
    After a little prod from anon monk I read the docs a little closer and found my answer in Plack::App::File
    enable "Static", path => sub { s!^/static!! }, root => './html-files', ;
    My mistake was thinking PM::Static behaved the same as PM::Pod - when i looked at the source of both i saw that PM::Pod was doing the substitution itself:
    Plack::Middleware::Pod my $r = $self->root || './'; $path =~ s!$path_match!$r!;
Re: Serving static files with Plack
by Anonymous Monk on Apr 20, 2016 at 21:53 UTC
    What documentation are you reading?

        Try  path => sub { s{^/static/}{}; }, root => 'html-files';

        When you only add root, its looking in root/static,