From b4403b9cd00d26fbd5514acbf1fb104c5ab5ae83 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 --- 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.20.1