From 7776e13e574bda7faa942c569f9b4bad93ac23fe Mon Sep 17 00:00:00 2001 From: drorganvidez Date: Thu, 29 Aug 2024 21:19:13 +0200 Subject: [PATCH] fix: Fix bug in https protocol (prod env) --- app/modules/hubfile/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/modules/hubfile/models.py b/app/modules/hubfile/models.py index 25bec1405..8e64140c3 100644 --- a/app/modules/hubfile/models.py +++ b/app/modules/hubfile/models.py @@ -36,11 +36,15 @@ def to_dict(self): flask_env = os.getenv('FLASK_ENV', 'development') domain = os.getenv('DOMAIN', 'localhost') + # If the domain looks like a subdomain (contains more than one dot), do not add ‘www’. + if domain.count('.') == 1: + domain = f"www.{domain}" + # If in production, use https, otherwise use http protocol = 'https' if flask_env == 'production' else 'http' # Construct the URL using the appropriate protocol and domain. - url = f"{protocol}://www.{domain}/hubfile/download/{self.id}" + url = f"{protocol}://{domain}/hubfile/download/{self.id}" return { "id": self.id,