six_001
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# routing.py
|
||||
"""
|
||||
ASGI config for django_cat project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
|
||||
"""
|
||||
from sixGuoDjango.settings import BASE_DIR
|
||||
|
||||
"""asgi路由"""
|
||||
import os
|
||||
|
||||
os.environ.setdefault(key='DJANGO_SETTINGS_MODULE', value=f"{BASE_DIR.name}.settings")
|
||||
from django.core.asgi import get_asgi_application
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from django_channels import consumers, tableConsumer
|
||||
from django.urls import path
|
||||
|
||||
application = ProtocolTypeRouter(
|
||||
{
|
||||
"http": get_asgi_application(), # 如果处理http请求就走这里
|
||||
"websocket": URLRouter(
|
||||
[
|
||||
# re_path(r'room/(?P<group>\w+)/$', consumers.ChatConsumer.as_asgi()),
|
||||
path(route="room/", view=consumers.ChatConsumer.as_asgi()), # 调用第一个类处理业务
|
||||
# path("web/<str:params>/", tableConsumer.TableConsumer.as_asgi()), # 调用第二个类处理业务
|
||||
],
|
||||
)
|
||||
},
|
||||
)
|
||||
# AllowedHostsOriginValidator:
|
||||
# 这是一个安全中间件,用于验证WebSocket连接请求的Origin头部是否包含在ALLOWED_HOSTS设置中。
|
||||
# 这是防止跨站伪造攻击(Cross-Site Request Forgery, CSRF)的一种措施,
|
||||
# 确保只有来自信任源(通常是应用自己的域名)的WebSocket连接请求才能被接受。
|
||||
# 如果请求的Origin不在允许列表中,此中间件会拒绝连接。
|
||||
Reference in New Issue
Block a user