feat: production routing support for subdomain and custom domain modes
Some checks failed
Some checks failed
Double-mount store routes at /store/* and /store/{store_code}/* so the
same handlers work in dev path-based, prod path-based, prod subdomain,
and prod custom-domain modes. Wire StorePlatform.custom_subdomain into
StoreContextMiddleware for per-platform subdomain overrides. Add admin
custom-domain management UI, fix stale /shop/ reset link, add
/merchants/ to reserved paths, and server-render window.STORE_CODE for
JS that previously parsed the URL.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -185,6 +185,35 @@ class StoreContextManager:
|
||||
# Method 2 & 3: Subdomain or path-based lookup
|
||||
if "subdomain" in context:
|
||||
subdomain = context["subdomain"]
|
||||
|
||||
# 2a. Check StorePlatform.custom_subdomain (platform-specific override)
|
||||
# e.g. acme-rewards.rewardflow.lu → StorePlatform with custom_subdomain="acme-rewards"
|
||||
platform = context.get("_platform")
|
||||
if platform and context.get("detection_method") == "subdomain":
|
||||
from app.modules.tenancy.models.store_platform import StorePlatform
|
||||
|
||||
store_platform = (
|
||||
db.query(StorePlatform)
|
||||
.filter(
|
||||
func.lower(StorePlatform.custom_subdomain) == subdomain.lower(),
|
||||
StorePlatform.platform_id == platform.id,
|
||||
StorePlatform.is_active.is_(True),
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if store_platform:
|
||||
store = (
|
||||
db.query(Store)
|
||||
.filter(Store.id == store_platform.store_id, Store.is_active.is_(True))
|
||||
.first()
|
||||
)
|
||||
if store:
|
||||
logger.info(
|
||||
f"[OK] Store found via custom_subdomain: {subdomain} → {store.name} (platform={platform.code})"
|
||||
)
|
||||
return store
|
||||
|
||||
# 2b. Fallback to Store.subdomain (global default)
|
||||
store = (
|
||||
db.query(Store)
|
||||
.filter(func.lower(Store.subdomain) == subdomain.lower())
|
||||
@@ -493,6 +522,12 @@ class StoreContextMiddleware(BaseHTTPMiddleware):
|
||||
store_context = StoreContextManager.detect_store_context(request)
|
||||
|
||||
if store_context:
|
||||
# Pass platform from middleware state so subdomain lookup can check
|
||||
# StorePlatform.custom_subdomain for platform-specific overrides
|
||||
platform = getattr(request.state, "platform", None)
|
||||
if platform:
|
||||
store_context["_platform"] = platform
|
||||
|
||||
db_gen = get_db()
|
||||
db = next(db_gen)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user