I am trying to implement a Django Projects with multiple Apps, with multiple Consumers with different WebSocket routing patterns for each paths.
Below is my working code, the code works, but is obviously is not correct, I have tried with different methods as the Django Chennels Documents Django Channels - Routing states but never got it to work,
#asgi.py
from api.middleware import TokenAuthMiddleWare
from api.routing import websocket_urlpatterns
from live_tracker.routing import live_websocket_urlpatterns
application = ProtocolTypeRouter(
{
'http': get_asgi_application(),
'websocket': TokenAuthMiddleWare(AuthMiddlewareStack(URLRouter(websocket_urlpatterns))),
}
)
application = ProtocolTypeRouter(
{
'http': get_asgi_application(),
'websocket': AuthMiddlewareStack(URLRouter(live_websocket_urlpatterns)),
}
)
From the 2 apps I have, in first app I have made it so that a token is needed to access the websocket_urlpatterns while in the second app I only need default django authentication: live_websocket_urlpatterns.
I went through StackOverflows this question How to use multiple websocket connections using Django Channels? the question is handling AuthMiddlewareStack only,to which I have 2, a custom TokenAuthMiddleWare and django's default AuthMiddlewareStack
is there a way I can merge the 2 applictaion to 1 applications?