Configuring directory aliases in Starman (or other PSGI servers)
I am used开发者_Go百科 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?
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.
精彩评论