Improved websocket consumer

This commit is contained in:
Keannu Christian Bernasol 2023-09-12 21:36:28 +08:00
parent 63d16eae17
commit 8d5a316d54
2 changed files with 34 additions and 11 deletions

View file

@ -1,6 +1,7 @@
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from channels.auth import AuthMiddlewareStack
from django.core.asgi import get_asgi_application
import api.routing
@ -13,9 +14,11 @@ django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter({
"http": django_asgi_app,
'websocket': AuthMiddlewareStack(
URLRouter(
[re_path(r'ws/', URLRouter(api.routing.websocket_urlpatterns))]
)
),
'websocket': AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(
[re_path(r'ws/', URLRouter(api.routing.websocket_urlpatterns))]
)
),
)
})