feat(multitenancy): Add TenantHeaderMiddleware to support centralized API with tenant switching

- Implemented TenantHeaderMiddleware to switch the database tenant schema based on the 'X-Business-Subdomain' request header.
- This allows API requests directed to the centralized 'api' subdomain (e.g., api.lvh.me) to correctly access tenant-specific data when the header is present.
- Registered the middleware in multitenancy settings after TenantMainMiddleware.
This commit is contained in:
poduck
2025-12-01 02:41:25 -05:00
parent 980b5d36aa
commit fa3195b3b3
2 changed files with 25 additions and 0 deletions

View File

@@ -94,6 +94,7 @@ MIDDLEWARE = [
# 1. Tenant resolution
'django_tenants.middleware.main.TenantMainMiddleware',
'core.middleware.TenantHeaderMiddleware', # Support tenant switching via header
# 2. Security middleware
'django.middleware.security.SecurityMiddleware',