feat: integrate PlatformContextMiddleware and update routes for multi-platform

Phase 2 implementation:
- Register PlatformContextMiddleware in main.py (runs before VendorContextMiddleware)
- Update VendorContextMiddleware to use platform_clean_path
- Update platform homepage route to use three-tier CMS resolution
- Update platform content page routes with platform context
- Update vendor root path handlers with platform_id support

Middleware execution order:
1. LoggingMiddleware
2. PlatformContextMiddleware (detect platform from domain/path)
3. VendorContextMiddleware (detect vendor, uses platform_clean_path)
4. ContextMiddleware
5. LanguageMiddleware
6. ThemeContextMiddleware

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-18 20:02:38 +01:00
parent 081f81af47
commit fe49008fef
2 changed files with 100 additions and 46 deletions

View File

@@ -9,6 +9,9 @@ Handles three routing modes:
3. Path-based (/vendor/vendor1/ or /vendors/vendor1/ → Vendor 1)
Also extracts clean_path for nested routing patterns.
IMPORTANT: This middleware runs AFTER PlatformContextMiddleware.
Uses request.state.platform_clean_path when available (set by PlatformContextMiddleware).
"""
import logging
@@ -39,10 +42,14 @@ class VendorContextManager:
2. Subdomain (vendor1.platform.com)
3. Path-based (/vendor/vendor1/ or /vendors/vendor1/)
Uses platform_clean_path from PlatformContextMiddleware when available.
This path has the platform prefix stripped (e.g., /oms/vendors/foo → /vendors/foo).
Returns dict with vendor info or None if not found.
"""
host = request.headers.get("host", "")
path = request.url.path
# Use platform_clean_path if available (set by PlatformContextMiddleware)
path = getattr(request.state, "platform_clean_path", None) or request.url.path
# Remove port from host if present (e.g., localhost:8000 -> localhost)
if ":" in host:
@@ -393,7 +400,9 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
- More organized code
- Standard ASGI pattern
Runs FIRST in middleware chain.
Runs AFTER PlatformContextMiddleware in the request chain.
Uses request.state.platform_clean_path for path-based vendor detection.
Sets:
request.state.vendor: Vendor object
request.state.vendor_context: Detection metadata