From 998c0cb7b36aea76c9e836e4d455fe808d23f034 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Mon, 14 Nov 2022 18:58:36 +0530 Subject: [PATCH] Fixed issue related to reverse proxy. 1) Fix reverse proxy redirection in server mode. 2) All reverse proxies in desktop mode. --- web/pgAdmin4.py | 6 +++--- web/pgadmin/__init__.py | 8 ++++++-- web/pgadmin/utils/__init__.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index fd3d387f5..0a00e049f 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -97,9 +97,6 @@ app.config['sessions'] = dict() if setup_db_required: setup.setup_db(app) -if config.SERVER_MODE: - app.wsgi_app = ReverseProxied(app.wsgi_app) - # Authentication sources if len(config.AUTHENTICATION_SOURCES) > 0: # Creating a temporary auth source list removing INTERNAL @@ -142,6 +139,9 @@ if 'PGADMIN_INT_KEY' in os.environ: else: app.PGADMIN_INT_KEY = '' +if not app.PGADMIN_RUNTIME: + app.wsgi_app = ReverseProxied(app.wsgi_app) + ########################################################################## # The entry point diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 5bbb76284..382123aeb 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -123,13 +123,17 @@ class PgAdmin(Flask): # like 'localhost/pgadmin4' then we have to append '/pgadmin4' # into endpoints ############################################################# - wsgi_root_path = current_app.config.get("APPLICATION_ROOT", "/") + wsgi_root_path = None + if url_for('browser.index') != '/browser/': + wsgi_root_path = url_for('browser.index').replace( + '/browser/', '' + ) def get_full_url_path(url): """ Generate endpoint URL at per WSGI alias """ - if wsgi_root_path != "/" and url: + if wsgi_root_path is not None and url: return wsgi_root_path + url else: return url diff --git a/web/pgadmin/utils/__init__.py b/web/pgadmin/utils/__init__.py index 47e564d3d..13ffa062d 100644 --- a/web/pgadmin/utils/__init__.py +++ b/web/pgadmin/utils/__init__.py @@ -846,4 +846,4 @@ def get_safe_post_login_redirect(): if url.startswith(item): return url - return os.environ.get("SCRIPT_NAME", "/") + return url_for('browser.index')