Browse Source
Add domain-specific URL configurations and middleware for Dovoodi and Imam Javad</message>
Add domain-specific URL configurations and middleware for Dovoodi and Imam Javad</message>
<message> - Introduced `urls_dovoodi.py` and `urls_imamjavad.py` for handling URL patterns specific to each domain. - Implemented `SiteMiddleware` to route requests based on the request domain, ensuring clean admin URLs. - Updated `base.py` settings to include the new middleware for domain-based routing. - Modified Nginx configurations for both domains to support the new routing logic and SSL settings.master
7 changed files with 208 additions and 148 deletions
-
32config/middleware/site_middleware.py
-
1config/settings/base.py
-
21config/urls.py
-
26config/urls_dovoodi.py
-
26config/urls_imamjavad.py
-
19nginx/dovodi.conf
-
231nginx/imamjavad.conf
@ -0,0 +1,32 @@ |
|||||
|
""" |
||||
|
Domain-based URL Configuration Middleware |
||||
|
|
||||
|
This middleware detects the request domain and routes to the appropriate |
||||
|
URLconf (URL configuration) for each site: |
||||
|
- Dovoodi domains → config.urls_dovoodi |
||||
|
- Imam Javad domains → config.urls_imamjavad |
||||
|
""" |
||||
|
|
||||
|
|
||||
|
class SiteMiddleware: |
||||
|
""" |
||||
|
Middleware to route requests to different URL configurations based on domain. |
||||
|
|
||||
|
This allows each domain to have clean /admin/ URLs instead of path-based |
||||
|
differentiation (/imam-javad/admin vs /dovoodi/admin). |
||||
|
""" |
||||
|
|
||||
|
def __init__(self, get_response): |
||||
|
self.get_response = get_response |
||||
|
|
||||
|
def __call__(self, request): |
||||
|
host = request.get_host() |
||||
|
|
||||
|
# Check if the request is from Dovoodi domain |
||||
|
if 'dovodi' in host or 'dovoodi' in host: |
||||
|
request.urlconf = 'config.urls_dovoodi' |
||||
|
# Otherwise, use Imam Javad configuration (default) |
||||
|
else: |
||||
|
request.urlconf = 'config.urls_imamjavad' |
||||
|
|
||||
|
return self.get_response(request) |
||||
@ -0,0 +1,26 @@ |
|||||
|
""" |
||||
|
URL configuration for Dovoodi domain |
||||
|
This configuration is loaded when accessing from dovodi.* or dovoodi.* domains |
||||
|
""" |
||||
|
from django.urls import path, include |
||||
|
from django.conf.urls.i18n import i18n_patterns |
||||
|
from config.urls import urlpatterns as base_urlpatterns, swagger_urlpatterns |
||||
|
from utils.admin import dovoodi_admin_site |
||||
|
from apps.api.views import CustomAPIDocumentationView |
||||
|
|
||||
|
|
||||
|
# Combine base patterns with Dovoodi specific admin |
||||
|
urlpatterns = base_urlpatterns + i18n_patterns( |
||||
|
# Admin panel accessible at /admin/ (Django will redirect to /en/admin/ or /fa/admin/) |
||||
|
path("admin/", dovoodi_admin_site.urls), |
||||
|
|
||||
|
# API documentation |
||||
|
path('docs/', CustomAPIDocumentationView.as_view(), name='docs-index'), |
||||
|
|
||||
|
# Swagger and API documentation |
||||
|
*swagger_urlpatterns, |
||||
|
|
||||
|
# Filer (Django file manager) |
||||
|
path('admin/filer/', include('filer.urls')), |
||||
|
path('filer/', include('filer.urls')), |
||||
|
) |
||||
@ -0,0 +1,26 @@ |
|||||
|
""" |
||||
|
URL configuration for Imam Javad domain |
||||
|
This configuration is loaded when accessing from imamjavad.* domains |
||||
|
""" |
||||
|
from django.urls import path, include |
||||
|
from django.conf.urls.i18n import i18n_patterns |
||||
|
from config.urls import urlpatterns as base_urlpatterns, swagger_urlpatterns |
||||
|
from utils.admin import project_admin_site |
||||
|
from apps.api.views import CustomAPIDocumentationView |
||||
|
|
||||
|
|
||||
|
# Combine base patterns with Imam Javad specific admin |
||||
|
urlpatterns = base_urlpatterns + i18n_patterns( |
||||
|
# Admin panel accessible at /admin/ (Django will redirect to /en/admin/ or /fa/admin/) |
||||
|
path("admin/", project_admin_site.urls), |
||||
|
|
||||
|
# API documentation |
||||
|
path('docs/', CustomAPIDocumentationView.as_view(), name='docs-index'), |
||||
|
|
||||
|
# Swagger and API documentation |
||||
|
*swagger_urlpatterns, |
||||
|
|
||||
|
# Filer (Django file manager) |
||||
|
path('admin/filer/', include('filer.urls')), |
||||
|
path('filer/', include('filer.urls')), |
||||
|
) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue