From efc9a7d320f896115bee1a9ce4031bf32c46d86a Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 28 Aug 2020 17:35:14 +0400 Subject: [PATCH] Bug 20582: Fix PSGI file when behind a reverse proxy ReverseProxy middleware can modify SERVER_PORT which is used to determines which app (opac or intranet) to run, so the choice should be made before ReverseProxy middleware Signed-off-by: Jerome Charaoui Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- app.psgi | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app.psgi b/app.psgi index 9a0d287fc4..0824a3ebc6 100644 --- a/app.psgi +++ b/app.psgi @@ -41,12 +41,24 @@ my $port2app = { }; builder { + # This middleware decides which app to run (opac or intranet) depending on + # SERVER_PORT. It must be run before ReverseProxy middleware which can + # modify SERVER_PORT + enable sub { + my $app = shift; + sub { + my $env = shift; + $env->{'koha.app'} = $port2app->{$env->{SERVER_PORT}} || $intranet; + return $app->($env); + } + }; + enable 'ReverseProxy'; enable '+Koha::Middleware::SetEnv'; enable '+Koha::Middleware::RealIP'; + sub { my $env = shift; - my $app = $port2app->{$env->{SERVER_PORT}} || $intranet; - $app->($env); + $env->{'koha.app'}->($env); }; } -- 2.39.5