1

寻找一种方法,如何PSGI $appmount 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...

4

1 回答 1

0

代码实际上是

push @{$self->{_mapping}}, [ $host, $location, qr/^\Q$location\E/, $app ];

如您所见,不支持正则表达式,$location 也许您可以通过提供'\\Eregex_here\\Q'位置来欺骗它,但我不知道如何欺骗它。

于 2015-05-06T14:15:14.223 回答