WIP: Add an async route for WS

This commit is contained in:
Alexis Métaireau 2024-03-21 10:06:27 +01:00 committed by Yohan Boniface
parent 71943c0ab3
commit aa246aaf05

View file

@ -1,7 +1,10 @@
import os import os
from channels.routing import ProtocolTypeRouter from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
from django.urls import re_path
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings")
# Initialize Django ASGI application early to ensure the AppRegistry # Initialize Django ASGI application early to ensure the AppRegistry
@ -12,5 +15,14 @@ application = ProtocolTypeRouter(
{ {
"http": django_asgi_app, "http": django_asgi_app,
# Just HTTP for now. (We can add other protocols later.) # Just HTTP for now. (We can add other protocols later.)
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(
[
re_path(r"^ws/$", consumers.AsyncChatConsumer.as_asgi()),
]
)
)
),
} }
) )