修复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
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["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
from application.websocketConfig import websocket_application
from application.routing import websocket_urlpatterns
http_application = get_asgi_application()
# async def application(scope,receive,send):
# if scope['type'] == 'http':
# await http_application(scope, receive, send)
# elif scope['type'] == 'websocket':
# await websocket_application(scope, receive, send)
# else:
# raise Exception("未知的scope类型,"+ scope['type'])
application = ProtocolTypeRouter({
"http":http_application,
'websocket': AuthMiddlewareStack(
URLRouter(
websocket_urlpatterns #指明路由文件是devops/routing.py
)
),
})

View File

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