Configuring directory aliases in Starman (or other PSGI servers)

277 views Asked by At

I am used to setting aliases to different directories in Apache httpd.conf. For example, the following works for me

Alias /lib /path/to/lib

Then I can include paths such as <script src="/lib/jquery/plugin/funky.js"></script> no matter what the application path.

I am trying out Starman (and other PSGI servers such as HTTP::Server::PSGI), and can't figure out any way to set configuration parameters such as alias to directories.

Can this be done? How?

1

There are 1 answers

0
miyagawa On

It can be easily done by using Plack::Middleware::Static.

use Plack::Builder;

builder {
    enable "Static", path => sub { s!^/lib/!! }, root => "/path/to/lib/";
    $app;
};

and you'll get "/lib/foo.js" loaded from "/path/to/lib/foo.js". This should work with Starman and any PSGI supported web servers.

More information is available in the online documenetation.