我正在尝试将我当前的 Apache/Modperl 站点转移到 Starman,并且需要使用针对不同文件扩展名的不同处理程序构建 app.psgi。类似于 Apache 中的东西:
<LocationMatch "(\.m|\.mh|\/)$">
SetHandler perl-script
PerlHandler MyApp::Mhandler
</LocationMatch>
<LocationMatch "(\.p|\.ph)$">
SetHandler perl-script
PerlHandler MyApp::Phandler
</LocationMatch>
我现在有:
#app for handle .m and .mh
my $Mapp = Some::PSGI->handler( sub {
...
});
#app for handling .p and .ph
my $Papp = SomeOther::PSGI->handler( sub {
...
});
但是如何使用构建器?
builder {
#any extension what is not .m .mh .p .ph - handle as static
#but, only when the request have any extension
enable "Plack::Middleware::Static",
path => __what here__, ???
root => "/my/doc/root";
#and what here to achieve the following "rules".
#??? $Papp
#default $Mapp
};
需要的“规则”:
- 如果请求没有任何扩展名,或者请求以 '/' 结尾
- 应该处理
$Mapp
- 应该处理
- 如果请求以某些扩展名结束,则
.m
并.mh
应由$Mapp
.p
并.ph
应由$Papp
- 所有其他带有扩展名的文件(如 .css .js .pdf .jpg ...)都应作为静态文件处理。
当然,将每个静态文件放到某个树中会容易得多,但是给出了当前的应用程序,现在我只想将它移动到 Startman,重构 - 稍后。