1

Looking for a way, how to run the same PSGI $app for multiple requests what aren't defined by the mount prefix. How to mount in such screnario? E.g. let say i have in my 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"
}

E.g., the requests matching

  • /some/path - want be handled by the $someapp (this is OK)
  • /[A-Z]\w+/\w+\.(xxx|yyy|zzz)$ - want be handled by the $otherapp
  • any other request want be handled by the $defaultapp (Ok too)

This is probably "damm-easy" - but my reading thru of the Plack::Builder doesn't give the answer. (Each mount in the maual and examples are strict /path based...)

EDIT: If this isn't possible by the mount is it possible to solve the above requirement in some clean (read not hackish) way? I don't need change the PATH_INFO, nor the SCRIPT_NAME (as URLMap is doing) - just need run the given $otherapp, for the matched requests.

EDIT2:

To be more clear. The $someapp and the $otherapp are already existing applications. Especially the $otherapp is an complex application what handles every request on its own way - but the requests what "belongs" to the $otherapp is possible to describe by regex.

I can't use the mount /fixed/prefix because the $otherapp creates different urls at runtime, e.g. for example based on the users activity it could create /Abc/xyz.eee and/or /Zzz/uuu.ddd etc.. Therefore i can't prefix the $otherapp as for example:

mount '/other' => $otherapp

Now, want "import" this old-fashinoed $otherapp to an new PSGI based server and moreover, the $defaultapp and the $someapp will do something with the data of the $otherapp. It sounds complicated, but in the reality it isn't - only need run the $otherapp based on the requests regex, e.g. something as Apache's SetHandler somehandler *.ext...

kobame
  • 5,766
  • 3
  • 31
  • 62
  • How about proxy-application, that redirects to the another one by the URL? – Vadim Pushtaev May 06 '15 at 14:37
  • I use Plack::Builder to mount several Dancer2 apps at different prefixes, e.g. `/foo` and `/bar`. Dancer2 has complex routing logic, including wildcard and regex matching, so that is where I handle variable routes. Perhaps you could do something similar in your apps? – ThisSuitIsBlackNot May 06 '15 at 15:44

1 Answers1

0

The code actually is

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

As you can see, no regex supported in $location but maybe you can trick it by providing '\\Eregex_here\\Q' as a location and I don't know the way to trick it.

Vadim Pushtaev
  • 2,332
  • 18
  • 32