3

I am practicing with Perl and PSGI/Plack. Just trying the simple PSGI example app:

app.psgi

#!/usr/bin/perl

my $counter = 0;

my $app = sub {
    my $env = shift;
    my $path = $env->{PATH_INFO} || $env->{REQUEST_URI};
    $counter++;
    my $content = "Hellow world.\nCounter=$counter\nPath: $path\n";
    return [ 200, [ 'Content-type', 'text/plain' ], [ $content ] ]
};

then run it by:

plackup app.psgi

if I point the browser to any path like /news/world:

http://localhost:5000/new/world

this is ok, I get the $path variable set to /news/world and I will handle the cgi response.

the problem if I point to static files like logo.png

http://localhost:5000/logo.png

I also get the $path variable set to /logo.png

The question is, why the plackup server does not serve the static image file logo.png automatically.

Do I have to do this manually? if so does that means on every request I have to ping the file system first check if -f $path.

This means I am building a complete server handler not just my script handler. What I am not understanding.

daliaessam
  • 1,636
  • 2
  • 21
  • 43

2 Answers2

5

Use the Plack::Middleware::Static module. It allows your app to serve static files from root directory.

Miguel Prz
  • 13,718
  • 29
  • 42
0

Plack::Middleware::Static works for static directory. But you can process File Handler instead. You can try to put in the body the GLOB scalar and header application/pdf.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
kurkop
  • 520
  • 4
  • 11