migrating vendor frontend to new architecture

This commit is contained in:
2025-10-31 20:51:30 +01:00
parent 9420483ae6
commit 9611c03a36
25 changed files with 1618 additions and 286 deletions

View File

@@ -30,7 +30,7 @@ class VendorContextManager:
host = request.headers.get("host", "")
path = request.url.path
# Remove port from host if present (e.g., localhost:8000 localhost)
# Remove port from host if present (e.g., localhost:8000 -> localhost)
if ":" in host:
host = host.split(":")[0]
@@ -118,7 +118,7 @@ class VendorContextManager:
logger.warning(f"Vendor for domain {domain} is not active")
return None
logger.info(f" Vendor found via custom domain: {domain} {vendor.name}")
logger.info(f"[OK] Vendor found via custom domain: {domain} -> {vendor.name}")
return vendor
else:
logger.warning(f"No active vendor found for custom domain: {domain}")
@@ -137,7 +137,7 @@ class VendorContextManager:
if vendor:
method = context.get("detection_method", "unknown")
logger.info(f" Vendor found via {method}: {subdomain} {vendor.name}")
logger.info(f"[OK] Vendor found via {method}: {subdomain} -> {vendor.name}")
else:
logger.warning(f"No active vendor found for subdomain: {subdomain}")
@@ -184,19 +184,49 @@ class VendorContextManager:
"""Check if request is for API endpoints."""
return request.url.path.startswith("/api/")
@staticmethod
def is_static_file_request(request: Request) -> bool:
"""Check if request is for static files."""
path = request.url.path.lower()
# Static file extensions
static_extensions = (
'.ico', '.css', '.js', '.png', '.jpg', '.jpeg', '.gif', '.svg',
'.woff', '.woff2', '.ttf', '.eot', '.webp', '.map', '.json',
'.xml', '.txt', '.pdf', '.webmanifest'
)
# Static paths
static_paths = ('/static/', '/media/', '/assets/', '/.well-known/')
# Check if it's a static file by extension
if path.endswith(static_extensions):
return True
# Check if it's in a static directory
if any(path.startswith(static_path) for static_path in static_paths):
return True
# Special case: favicon.ico at any level
if 'favicon.ico' in path:
return True
return False
async def vendor_context_middleware(request: Request, call_next):
"""
Middleware to inject vendor context into request state.
Handles three routing modes:
1. Custom domains (customdomain1.com Vendor 1)
2. Subdomains (vendor1.platform.com Vendor 1)
3. Path-based (/vendor/vendor1/ Vendor 1)
1. Custom domains (customdomain1.com -> Vendor 1)
2. Subdomains (vendor1.platform.com -> Vendor 1)
3. Path-based (/vendor/vendor1/ -> Vendor 1)
"""
# Skip vendor detection for admin, API, and system requests
# Skip vendor detection for admin, API, static files, and system requests
if (VendorContextManager.is_admin_request(request) or
VendorContextManager.is_api_request(request) or
VendorContextManager.is_static_file_request(request) or
request.url.path in ["/", "/health", "/docs", "/redoc", "/openapi.json"]):
return await call_next(request)
@@ -217,12 +247,12 @@ async def vendor_context_middleware(request: Request, call_next):
)
logger.debug(
f"🏪 Vendor context: {vendor.name} ({vendor.subdomain}) "
f"[VENDOR] Vendor context: {vendor.name} ({vendor.subdomain}) "
f"via {vendor_context['detection_method']}"
)
else:
logger.warning(
f"⚠️ Vendor not found for context: {vendor_context}"
f"[WARNING] Vendor not found for context: {vendor_context}"
)
request.state.vendor = None
request.state.vendor_context = vendor_context