修复BUG: 修复websocket问题

pull/79/head
猿小天 2022-11-17 10:53:47 +08:00
parent 722a0ac623
commit 040cb075e1
2 changed files with 12 additions and 19 deletions

View File

@ -8,20 +8,21 @@ https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
""" """
import os import os
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
from application.websocketConfig import websocket_application from application.routing import websocket_urlpatterns
http_application = get_asgi_application() http_application = get_asgi_application()
# async def application(scope,receive,send): application = ProtocolTypeRouter({
# if scope['type'] == 'http': "http":http_application,
# await http_application(scope, receive, send) 'websocket': AuthMiddlewareStack(
# elif scope['type'] == 'websocket': URLRouter(
# await websocket_application(scope, receive, send) websocket_urlpatterns #指明路由文件是devops/routing.py
# else: )
# raise Exception("未知的scope类型,"+ scope['type']) ),
})

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import path from django.urls import path
@ -10,10 +9,3 @@ websocket_urlpatterns = [
path('ws/<str:service_uid>/', MegCenter.as_asgi()), #consumers.DvadminWebSocket 是该路由的消费者 path('ws/<str:service_uid>/', MegCenter.as_asgi()), #consumers.DvadminWebSocket 是该路由的消费者
] ]
application = ProtocolTypeRouter({
'websocket': AuthMiddlewareStack(
URLRouter(
websocket_urlpatterns #指明路由文件是devops/routing.py
)
),
})