diff --git a/zerver/lib/subdomains.py b/zerver/lib/subdomains.py index aa3a8f6ef0..c583a2af4b 100644 --- a/zerver/lib/subdomains.py +++ b/zerver/lib/subdomains.py @@ -56,6 +56,7 @@ def is_root_domain_available() -> bool: def is_static_or_current_realm_url(url: str, realm: Optional[Realm]) -> bool: + assert settings.STATIC_URL is not None split_url = urllib.parse.urlsplit(url) split_static_url = urllib.parse.urlsplit(settings.STATIC_URL) diff --git a/zproject/computed_settings.py b/zproject/computed_settings.py index e970abc0a5..ba3f369308 100644 --- a/zproject/computed_settings.py +++ b/zproject/computed_settings.py @@ -60,6 +60,7 @@ from .configured_settings import ( SOCIAL_AUTH_SAML_ENABLED_IDPS, SOCIAL_AUTH_SAML_SECURITY_CONFIG, SOCIAL_AUTH_SUBDOMAIN, + STATIC_URL, STATSD_HOST, TORNADO_PORTS, USING_PGROONGA, @@ -537,10 +538,11 @@ CAMO_KEY = get_secret("camo_key") if CAMO_URI != "" else None # STATIC CONTENT AND MINIFICATION SETTINGS ######################################################################## -if PRODUCTION or IS_DEV_DROPLET or os.getenv("EXTERNAL_HOST") is not None: - STATIC_URL = urljoin(ROOT_DOMAIN_URI, "/static/") -else: - STATIC_URL = "http://localhost:9991/static/" +if STATIC_URL is None: + if PRODUCTION or IS_DEV_DROPLET or os.getenv("EXTERNAL_HOST") is not None: + STATIC_URL = urljoin(ROOT_DOMAIN_URI, "/static/") + else: + STATIC_URL = "http://localhost:9991/static/" LOCAL_AVATARS_DIR = os.path.join(LOCAL_UPLOADS_DIR, "avatars") if LOCAL_UPLOADS_DIR else None LOCAL_FILES_DIR = os.path.join(LOCAL_UPLOADS_DIR, "files") if LOCAL_UPLOADS_DIR else None diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 14c73fa8cb..9d5f9fb2c2 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -19,6 +19,8 @@ DEBUG = DEVELOPMENT EXTERNAL_HOST_WITHOUT_PORT = deport(EXTERNAL_HOST) +STATIC_URL: Optional[str] = None + # These settings are intended for the server admin to set. We document them in # prod_settings_template.py, and in the initial /etc/zulip/settings.py on a new # install of the Zulip server. diff --git a/zproject/dev_urls.py b/zproject/dev_urls.py index 77c487be12..281250fb60 100644 --- a/zproject/dev_urls.py +++ b/zproject/dev_urls.py @@ -116,6 +116,7 @@ else: response["Access-Control-Allow-Origin"] = "*" return response + assert settings.STATIC_URL is not None urls += static(urlsplit(settings.STATIC_URL).path, view=serve_static) i18n_urls = [