64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
"""
|
|
ASGI config for car_inventory project.
|
|
|
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
|
"""
|
|
|
|
# asgi.py
|
|
|
|
import os
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car_inventory.settings")
|
|
|
|
import django
|
|
|
|
django.setup()
|
|
|
|
|
|
from django.urls import path
|
|
from channels.routing import ProtocolTypeRouter, URLRouter
|
|
from channels.auth import AuthMiddlewareStack
|
|
from api import routing
|
|
from inventory.notifications.sse import NotificationSSEApp
|
|
from django.urls import re_path
|
|
from django.core.asgi import get_asgi_application
|
|
|
|
# application = ProtocolTypeRouter(
|
|
# {
|
|
# "http": get_asgi_application(),
|
|
# # "websocket": AuthMiddlewareStack(URLRouter(routing.websocket_urlpatterns)),
|
|
# }
|
|
# )
|
|
application = ProtocolTypeRouter(
|
|
{
|
|
"http": AuthMiddlewareStack(
|
|
URLRouter(
|
|
[
|
|
path("sse/notifications/", NotificationSSEApp()),
|
|
re_path(
|
|
r"", get_asgi_application()
|
|
), # All other routes go to Django
|
|
]
|
|
)
|
|
),
|
|
}
|
|
)
|
|
|
|
|
|
try:
|
|
from django.conf import settings
|
|
from django.contrib.sites.models import Site
|
|
|
|
if not settings.DEBUG:
|
|
site = Site.objects.get(id=settings.SITE_ID)
|
|
if site.domain != settings.PRODUCTION_DOMAIN:
|
|
site.domain = settings.PRODUCTION_DOMAIN
|
|
site.name = settings.SITE_NAME
|
|
site.save()
|
|
except Exception as e:
|
|
# Log error but don't crash the app
|
|
if settings.DEBUG:
|
|
print(f"Site configuration error in WSGI: {e}") |