123456789101112131415161718192021 |
- import os
- from django.core.asgi import get_asgi_application
- from utils.websocket import websocket_application
- from asgihandler.core import ASGIHandler
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'greaterwms.settings')
- # 获取 Django 的 ASGI 应用
- http_application = get_asgi_application()
- # 定义一个异步应用,根据请求类型分发请求到相应的处理程序
- async def application(scope, receive, send):
- if scope['type'] in ['http', 'https']:
- ASGIHandler.asgi_get_handler(scope)
- await http_application(scope, receive, send)
- elif scope['type'] in ['websocket']:
- await websocket_application(scope, receive, send)
- else:
- raise Exception('Unknown Type' + scope['type'])
|