[pgAdmin][RM4755] pgAdmin does not work behind reverse proxy if in built server is used as it is

Aditya Toshniwal <[email protected]>
Newsgroups gmane.comp.db.postgresql.pgadmin.devel
Message-ID <CAM9w-_kFSCfSf2gvFu_-69mhu2jW87dZ_wc_R0DTPwGE04oiUQ@mail.gmail.com>
Hi Hackers,

Attached is the patch to allow pgAdmin to work behind proxy with its in
built server. I have used werkzeug fixer -
https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#module-werkzeug.middleware.proxy_fix

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"
RM4755.patch (application/octet-stream, 1.1 KB)
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index 28bb51c7..70b6d7cc 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -27,6 +27,7 @@ from flask_security.utils import login_user, logout_user
 from werkzeug.datastructures import ImmutableDict
 from werkzeug.local import LocalProxy
 from werkzeug.utils import find_modules
+from werkzeug.middleware.proxy_fix import ProxyFix
 
 from pgadmin.model import db, Role, Server, ServerGroup, \
     User, Keys, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
@@ -205,6 +206,11 @@ def create_app(app_name=None):
     """Create the Flask application, startup logging and dynamically load
     additional modules (blueprints) that are found in this directory."""
     app = PgAdmin(__name__, static_url_path='/static')
+
+    # Allow to run behind proxy
+    # https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#module-werkzeug.middleware.proxy_fix
+    app.wsgi_app = ProxyFix(app.wsgi_app)
+
     # Removes unwanted whitespace from render_template function
     app.jinja_env.trim_blocks = True
     app.config.from_object(config)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.