asgi.py 734 B

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