From fcda624ed6cee18980a6489572180d8be4c53e7c Mon Sep 17 00:00:00 2001 From: Krzysztof SOCHA Date: Wed, 4 Sep 2024 20:25:09 +0200 Subject: [PATCH] Patch URL helper to assume use_appname=False if the host is a Fully Qualified Domain Name --- py4web/core.py | 3 +++ requirements.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/py4web/core.py b/py4web/core.py index 10dae504..92ef1b77 100644 --- a/py4web/core.py +++ b/py4web/core.py @@ -37,6 +37,7 @@ import zipfile from collections import OrderedDict from contextlib import redirect_stderr, redirect_stdout +from fqdn import FQDN import portalocker from watchgod import awatch @@ -860,6 +861,8 @@ def URL( # pylint: disable=invalid-name URL('a','b',vars=dict(x=1),scheme='https') -> https://{domain}/{script_name?}/{app_name?}/a/b?x=1 URL('a','b',vars=dict(x=1),use_appname=False) -> /{script_name?}/a/b?x=1 """ + if FQDN(request.urlparts[1]).is_valid: + use_appname = False if use_appname is None: # force use_appname on domain-unmapped apps use_appname = not request.environ.get("HTTP_X_PY4WEB_APPNAME") diff --git a/requirements.txt b/requirements.txt index da54f3d4..75464d09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ rocket3 >= 20230507.1 yatl >= 20230507.3 pydal >= 20240713.1 watchgod >= 0.6 +fqdn # optional modules: # gunicorn