[Dancer-users] Problems mounting multiple webapps

Alex Kalderimis alex at flymine.org
Tue Jun 14 19:44:02 CEST 2011


I can get this test to pass with a small patch to Dancer::App
(currently floating about as a pull-request on github) that privileges
the current app so that routes are found appropriately. 

For reference the changes made and the test run are at:
  https://github.com/alexkalderimis/Dancer/commit/007fce0f487d3de7a79e01c17c730da2b7e23ab8

Alex

On Tue, Jun 14, 2011 at 11:41:35AM +0100, Alex Kalderimis wrote:
> 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
> 
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users


More information about the Dancer-users mailing list