From 87684e2647d5de77bf1452fd38ab75798681cbc4 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 7 Sep 2023 01:29:36 +0200 Subject: [PATCH 1/2] feat: add werkzeug proxyfix to development server --- frappe/app.py | 12 +++++++++++- frappe/commands/utils.py | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frappe/app.py b/frappe/app.py index e5d2632e08..6f3846732b 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -9,6 +9,7 @@ import re from werkzeug.exceptions import HTTPException, NotFound from werkzeug.local import LocalManager from werkzeug.middleware.profiler import ProfilerMiddleware +from werkzeug.middleware.proxy_fix import ProxyFix from werkzeug.middleware.shared_data import SharedDataMiddleware from werkzeug.wrappers import Request, Response @@ -392,7 +393,13 @@ def sync_database(rollback: bool) -> bool: def serve( - port=8000, profile=False, no_reload=False, no_threading=False, site=None, sites_path="." + port=8000, + profile=False, + no_reload=False, + no_threading=False, + site=None, + sites_path=".", + proxy=False, ): global application, _site, _sites_path _site = site @@ -406,6 +413,9 @@ def serve( if not os.environ.get("NO_STATICS"): application = application_with_statics() + if proxy or os.environ.get("USE_PROXY"): + application = ProxyFix(application, x_for=1, x_proto=1, x_host=1, x_port=1, x_prefix=1) + application.debug = True application.config = {"SERVER_NAME": "localhost:8000"} diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 925c75d421..9c433f01a4 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -923,6 +923,12 @@ def run_ui_tests( @click.command("serve") @click.option("--port", default=8000) @click.option("--profile", is_flag=True, default=False) +@click.option( + "--proxy", + is_flag=True, + default=False, + help="The development server may be run behind a proxy, e.g. ngrok / localtunnel", +) @click.option("--noreload", "no_reload", is_flag=True, default=False) @click.option("--nothreading", "no_threading", is_flag=True, default=False) @click.option("--with-coverage", is_flag=True, default=False) @@ -931,6 +937,7 @@ def serve( context, port=None, profile=False, + proxy=False, no_reload=False, no_threading=False, sites_path=".", @@ -952,6 +959,7 @@ def serve( frappe.app.serve( port=port, profile=profile, + proxy=proxy, no_reload=no_reload, no_threading=no_threading, site=site, From 5e7ff1c81d0b4842303701f0af859b7c33adacf7 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 7 Sep 2023 00:53:42 +0200 Subject: [PATCH 2/2] fix: add well-known openid-configuration redirect --- frappe/hooks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frappe/hooks.py b/frappe/hooks.py index d18ad1addc..fd32ef9cf9 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -57,6 +57,10 @@ website_route_rules = [ website_redirects = [ {"source": r"/desk(.*)", "target": r"/app\1"}, + { + "source": "/.well-known/openid-configuration", + "target": "/api/method/frappe.integrations.oauth2.openid_configuration", + }, ] base_template = "templates/base.html"