refactor: rename platform_domain → main_domain to avoid confusion with platform.domain
Some checks failed
Some checks failed
The setting `settings.platform_domain` (the global/main domain like "wizard.lu") was easily confused with `platform.domain` (per-platform domain like "rewardflow.lu"). Renamed to `settings.main_domain` / `MAIN_DOMAIN` env var across the entire codebase. Also updated docs to reflect the refactored store detection logic with `is_platform_domain` / `is_subdomain_of_platform` guards. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -113,26 +113,37 @@ platform.com/storefront/store3 → Store 3 Storefront
|
||||
|
||||
### Store Detection Logic
|
||||
|
||||
The `StoreContextMiddleware` detects stores using this priority:
|
||||
The `StoreContextMiddleware` detects stores via `_detect_store_from_host_and_path()`.
|
||||
Before trying the three detection methods, two guards determine which methods apply:
|
||||
|
||||
- **`is_platform_domain`**: `host == platform.domain` (e.g., `rewardflow.lu` itself) — skips Methods 1 & 2
|
||||
- **`is_subdomain_of_platform`**: host is a subdomain of `platform.domain` (e.g., `acme.rewardflow.lu`) — skips Method 1
|
||||
|
||||
```python
|
||||
def detect_store(request):
|
||||
host = request.headers.get("host")
|
||||
def detect_store(host, path, platform):
|
||||
platform_own_domain = platform.domain # e.g. "rewardflow.lu"
|
||||
is_platform_domain = (host == platform_own_domain)
|
||||
is_subdomain_of_platform = (
|
||||
host != platform_own_domain
|
||||
and host.endswith(f".{platform_own_domain}")
|
||||
)
|
||||
|
||||
# 1. Try custom domain first
|
||||
store = find_by_custom_domain(host)
|
||||
if store:
|
||||
return store, "custom_domain"
|
||||
# 1. Custom domain — skipped when host is platform domain or subdomain of it
|
||||
if not is_platform_domain and not is_subdomain_of_platform:
|
||||
main_domain = settings.main_domain # e.g. "wizard.lu"
|
||||
if host != main_domain and not host.endswith(f".{main_domain}"):
|
||||
store = find_by_custom_domain(host)
|
||||
if store:
|
||||
return store, "custom_domain"
|
||||
|
||||
# 2. Try subdomain
|
||||
if host != settings.platform_domain:
|
||||
store_code = host.split('.')[0]
|
||||
store = find_by_code(store_code)
|
||||
# 2. Subdomain — skipped when host IS the platform domain
|
||||
if not is_platform_domain and "." in host:
|
||||
subdomain = host.split('.')[0]
|
||||
store = find_by_code(subdomain)
|
||||
if store:
|
||||
return store, "subdomain"
|
||||
|
||||
# 3. Try path-based
|
||||
path = request.url.path
|
||||
# 3. Path-based — always runs as fallback
|
||||
if path.startswith("/store/") or path.startswith("/storefront/"):
|
||||
store_code = extract_code_from_path(path)
|
||||
store = find_by_code(store_code)
|
||||
|
||||
Reference in New Issue
Block a user