Don't build the psgi app twice
Florian Ragwitz [Fri, 3 Dec 2010 16:00:19 +0000 (16:00 +0000)]
lib/Catalyst.pm
lib/Catalyst/Engine.pm

index f91eb26..2c96b15 100644 (file)
@@ -2402,7 +2402,7 @@ Starts the engine.
 
 =cut
 
-sub run { my $c = shift; return $c->engine->run( $c, @_ ) }
+sub run { my $c = shift; return $c->engine->run( $c, $c->psgi_app, @_ ) }
 
 =head2 $c->set_action( $action, $code, $namespace, $attrs )
 
index 1fdbfeb..7a98187 100644 (file)
@@ -780,13 +780,12 @@ run method on the server passed in..
 =cut
 
 sub run {
-    my ($self, $app, @args) = @_;
+    my ($self, $app, $psgi, @args) = @_;
+    # FIXME - Do something sensible with the options we're passed
     my $server = pop @args if blessed $args[-1];
     $server ||= Plack::Loader->auto(); # We're not being called from a script,
                                        # so auto detect what backend to run on.
                                        # This does *NOT* cover mod_perl.
-    # FIXME - Do something sensible with the options we're passed
-    my $psgi = $self->build_psgi_app($app, @args);
     $server->run($psgi);
 }
 
@@ -812,12 +811,12 @@ sub build_psgi_app {
 
     $psgi_app = Plack::Middleware::Conditional->wrap(
         $psgi_app,
+        builder   => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) },
         condition => sub {
             my ($env) = @_;
             return if $app->config->{ignore_frontend_proxy};
             return $env->{REMOTE_ADDR} eq '127.0.0.1' || $app->config->{using_frontend_proxy};
         },
-        builder   => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) },
     );
 
     return $psgi_app;