[Dancer-users] Problems mounting multiple webapps
Alex Kalderimis
alex at flymine.org
Tue Jun 14 12:41:35 CEST 2011
After looking into this I'm pretty convinced this is a genuine bug and
that the root of it (no pun intended) is this code in Dancer::App which
returns the handler for a request:
sub find_route_through_apps {
my ($class, $request) = @_;
for my $app (Dancer::App->applications) {
my $route = $app->find_route($request);
if ($route) {
Dancer::App->current($route->app);
return $route;
}
return $route if $route;
}
return;
}
This checks all loaded apps for matching routes, regardless of the
mountpoint they are associated with. For apps with prefixes, this will
work, as they are prefix aware. But for side-by-side apps, apps will
respond in a non deterministic manner due to the implementation of
->applications, which is a a values call on a hash, and if they respond
to the same route (such as '/' in the test case) they will clash.
I will see if I can submit a reasonable patch for this.
Alex
On Tue, 2011-06-14 at 15:57 +0900, Takeshi OKURA wrote:
> use Dancer ':syntax';
> use Plack::Builder;
>
> my $app1 = sub {
> my $env = shift;
> set appname => 'App1';
> get '/' => sub { return "Hello App1"; };
> my $request = Dancer::Request->new($env);
> Dancer->dance($request);
> };
>
> my $app2 = sub {
> my $env = shift;
> set appname => 'App2';
> get '/' => sub { return "Hello App2"; };
> my $request = Dancer::Request->new($env);
> Dancer->dance($request);
> };
>
> builder {
> mount "/app1" => builder {$app1};
> mount "/app2" => builder {$app2};
> };
--
Alex Kalderimis
Software Developer
InterMine
Cambridge Systems Biology Centre
Tennis Court Road - CB2 1QR
University of Cambridge
ajk59 at cam.ac.uk
More information about the Dancer-users
mailing list