通过正则表达式安装PSGI应用程序 - 不同路径 - >一个应用

时间:2015-05-06 14:09:05

标签: perl psgi

正在寻找一种方法,如何针对PSGI $app定义的多个请求运行相同的mount prefix。如何mount在这样的screnario?例如。让我说我的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处理(也可以)

这可能是#dam; damm-easy" - 但我对Plack::Builder的阅读并没有给出答案。 (maual和示例中的每个mount都是基于strict /path的...)

编辑:如果mount无法做到这一点,是否有可能在某些 clean 中解决上述要求(读取不是hackish)办法?我不需要更改PATH_INFO,也不需要SCRIPT_NAME(正如URLMap正在做的那样) - 只需要为匹配的请求运行给定的$otherapp

EDIT2

更清楚。 $someapp$otherapp已经是现有的应用程序。特别是$otherapp是一个复杂的应用程序,它以自己的方式处理每个请求 - 但请求是什么"属于"可以通过正则表达式来描述$otherapp

我无法使用mount /fixed/prefix,因为$otherapp会在运行时创建不同的网址,例如例如,根据用户活动,它可以创建/Abc/xyz.eee和/或/Zzz/uuu.ddd等。因此我不能在$otherapp前加上例如:

mount '/other' => $otherapp

现在,想要"导入"这个旧的fashinoed $otherapp到一个新的基于PSGI的服务器,此外,$defaultapp$someapp将对$otherapp的数据执行某些操作。这听起来很复杂,但事实并非如此 - 只需要根据请求正则表达式运行$otherapp,例如作为Apache的SetHandler somehandler *.ext ...

1 个答案:

答案 0 :(得分:0)

code实际上是

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

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

相关问题