寻找一种方法,如何PSGI $app
对mount prefix
. 如何mount
在这样的场景中?例如,假设我在我的app.psgi
use Plack::Builder;
my $defaultapp = sub { ... };
my $someapp = sub { ... };
my $otherapp = sub { ... };
builder {
mount '/some' => $someapp; # ok
#and here need something like:
mount "_regex_here" => $otherapp; #???
mount '/' => $defaultapp; #OK - last mount is the "default"
}
例如,请求匹配
/some/path
- 希望被处理$someapp
(这没关系)/[A-Z]\w+/\w+\.(xxx|yyy|zzz)$
- 希望被处理$otherapp
- 任何其他请求都希望由
$defaultapp
(也可以)处理
这可能是“很容易” - 但我通过Plack::Builder阅读并没有给出答案。(手册和示例中的每个mount
都是strict /path
基于...)
编辑:如果这是不可能的,mount
是否有可能以某种干净(阅读而不是骇人听闻)的方式解决上述要求?我不需要更改PATH_INFO
, 也不需要SCRIPT_NAME
(正如 URLMap 所做的那样) - 只需要$otherapp
为匹配的请求运行给定的 , 。
编辑2:
要更清楚。和$someapp
是$otherapp
已经存在的应用程序。特别是这$otherapp
是一个复杂的应用程序,它以自己的方式处理每个请求 - 但请求“属于”的$otherapp
内容可以通过正则表达式来描述。
我不能使用,mount /fixed/prefix
因为它$otherapp
会在运行时创建不同的 url,例如基于它可以创建的用户活动/Abc/xyz.eee
和/或/Zzz/uuu.ddd
等。因此我不能$otherapp
为例如添加前缀:
mount '/other' => $otherapp
现在,想要将这个老式的“导入”$otherapp
到一个新的基于 PSGI 的服务器上,而且,$defaultapp
它将$someapp
对$otherapp
. 这听起来很复杂,但实际上并非如此 - 只需要$otherapp
基于请求正则表达式运行,例如 Apache 的SetHandler somehandler *.ext
...