2025-09-11 20:58:40 +03:00

55 lines
1.3 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
from django.contrib.staticfiles.handlers import ASGIStaticFilesHandler
# application = ProtocolTypeRouter(
# {
# "http": get_asgi_application(),
# # "websocket": AuthMiddlewareStack(URLRouter(routing.websocket_urlpatterns)),
# }
# )
app = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": AuthMiddlewareStack(
URLRouter(
[
path("sse/notifications/", NotificationSSEApp()),
re_path(
r"", app
), # All other routes go to Django
]
)
),
}
)
if django.conf.settings.DEBUG:
application = ASGIStaticFilesHandler(app)