This commit is contained in:
2025-07-15 19:28:43 +08:00
parent 3e4c207cfc
commit 872ec5f7af
3 changed files with 12 additions and 23 deletions

View File

@@ -9,16 +9,9 @@ https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
import os import os
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
from .urls import ws_urlpatterns
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")
application = ProtocolTypeRouter( application =get_asgi_application()
{
"http": get_asgi_application(),
# "websocket": AuthMiddlewareStack(URLRouter(ws_urlpatterns)),
}
)

View File

@@ -130,14 +130,15 @@ else:
# 配置缓存 # 配置缓存
CACHES = PROD_CACHES CACHES = PROD_CACHES
CHANNEL_LAYERS = { # WebSocket 的缓存
"default": { # CHANNEL_LAYERS = {
"BACKEND": "channels_redis.core.RedisChannelLayer", # "default": {
"CONFIG": { # "BACKEND": "channels_redis.core.RedisChannelLayer",
"hosts": [(os.getenv("REDIS_HOST"), 6379)], # "CONFIG": {
}, # "hosts": [(os.getenv("REDIS_HOST"), 6379)],
}, # },
} # },
# }
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

View File

@@ -20,7 +20,6 @@ from django.urls import path
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from ninja import NinjaAPI from ninja import NinjaAPI
from .ws import Consumer
api = NinjaAPI() api = NinjaAPI()
@@ -36,7 +35,3 @@ apis = [
] ]
urlpatterns = apis + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns = apis + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
ws_urlpatterns = [
path("ws/", Consumer.as_asgi()),
]