mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: mise en place de la messagerie [#17]
This commit is contained in:
@ -8,9 +8,40 @@ https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from channels.security.websocket import AllowedHostsOriginValidator
|
||||
from django.urls import re_path
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles.handlers import ASGIStaticFilesHandler
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'N3wtSchool.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
# Initialize Django ASGI application early to ensure the AppRegistry
|
||||
# is populated before importing code that may import ORM models.
|
||||
django_asgi_app = get_asgi_application()
|
||||
|
||||
# Import consumers after Django is initialized
|
||||
from GestionMessagerie.consumers import ChatConsumer
|
||||
from GestionMessagerie.middleware import JWTAuthMiddlewareStack
|
||||
|
||||
# WebSocket URL patterns
|
||||
websocket_urlpatterns = [
|
||||
re_path(r'ws/chat/(?P<user_id>\w+)/$', ChatConsumer.as_asgi()),
|
||||
]
|
||||
|
||||
# Créer l'application ASGI avec gestion des fichiers statiques
|
||||
if settings.DEBUG:
|
||||
# En mode DEBUG, utiliser ASGIStaticFilesHandler pour servir les fichiers statiques
|
||||
http_application = ASGIStaticFilesHandler(django_asgi_app)
|
||||
else:
|
||||
http_application = django_asgi_app
|
||||
|
||||
application = ProtocolTypeRouter({
|
||||
"http": http_application,
|
||||
"websocket": AllowedHostsOriginValidator(
|
||||
JWTAuthMiddlewareStack(
|
||||
URLRouter(websocket_urlpatterns)
|
||||
)
|
||||
),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user