diff --git a/frappe/app.py b/frappe/app.py index e2b42ab2a0..28fa9c2426 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -9,6 +9,7 @@ import re from werkzeug.exceptions import HTTPException, NotFound 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 from werkzeug.wsgi import ClosingIterator @@ -413,7 +414,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 @@ -427,6 +434,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": "127.0.0.1:8000"} diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 69438aeca2..413b85ab37 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -929,6 +929,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) @@ -937,6 +943,7 @@ def serve( context, port=None, profile=False, + proxy=False, no_reload=False, no_threading=False, sites_path=".", @@ -958,6 +965,7 @@ def serve( frappe.app.serve( port=port, profile=profile, + proxy=proxy, no_reload=no_reload, no_threading=no_threading, site=site, diff --git a/frappe/hooks.py b/frappe/hooks.py index 6cccad8468..60941df10d 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -61,6 +61,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"