Load middlewares where they're actually used
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 696fd57..972b390 100644 (file)
@@ -34,6 +34,8 @@ use Catalyst::EngineLoader;
 use utf8;
 use Carp qw/croak carp shortmess/;
 use Try::Tiny;
+use Plack::Middleware::Conditional;
+use Plack::Middleware::ReverseProxy;
 
 BEGIN { require 5.008004; }
 
@@ -2642,7 +2644,7 @@ sub _setup_psgi_app {
             if -e $psgi_file;
     }
 
-    return $app->_wrapped_legacy_psgi_app;
+    return $app->_wrapped_legacy_psgi_app($app->psgi_app);
 }
 
 # Note - this is for back compatibility. Catalyst should not know or care about
@@ -2650,10 +2652,10 @@ sub _setup_psgi_app {
 #        use the ReverseProxy middleware yourself if you want it in a .psgi
 #        file.
 sub _wrapped_legacy_psgi_app {
-    my ($app) = @_;
+    my ($app, $psgi_app) = @_;
 
     return Plack::Middleware::Conditional->wrap(
-        $app->psgi_app,
+        $psgi_app,
         builder   => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) },
         condition => sub {
             my ($env) = @_;