perf: 支持 ws

pull/11057/head
ibuler 1 year ago
parent 7ae52eb941
commit 86a17b9955

@ -1,7 +1,21 @@
import os
import django
from channels.routing import get_default_application
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from .routing import urlpatterns
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
django.setup()
application = get_default_application()
application = ProtocolTypeRouter({
# Django's ASGI application to handle traditional HTTP requests
"http": get_asgi_application(),
# WebSocket chat handler
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(urlpatterns)
)
),
})

@ -1,27 +1,9 @@
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from notifications.urls.ws_urls import urlpatterns as notifications_urlpatterns
from ops.urls.ws_urls import urlpatterns as ops_urlpatterns
from settings.urls.ws_urls import urlpatterns as setting_urlpatterns
from terminal.urls.ws_urls import urlpatterns as terminal_urlpatterns
from .middleware import WsSignatureAuthMiddleware
urlpatterns = []
urlpatterns += ops_urlpatterns + \
notifications_urlpatterns + \
setting_urlpatterns + \
terminal_urlpatterns
application = ProtocolTypeRouter({
"http": get_asgi_application(),
'websocket': AllowedHostsOriginValidator(
WsSignatureAuthMiddleware(
AuthMiddlewareStack(
URLRouter(urlpatterns)
)
)
),
})
urlpatterns = ops_urlpatterns + \
notifications_urlpatterns + \
setting_urlpatterns + \
terminal_urlpatterns

@ -142,6 +142,9 @@ MIDDLEWARE = [
'jumpserver.middleware.EndMiddleware',
]
if DEBUG or DEBUG_DEV:
INSTALLED_APPS.insert(0, 'daphne')
ROOT_URLCONF = 'jumpserver.urls'
TEMPLATES = [

@ -127,7 +127,7 @@ CHANNEL_LAYERS = {
},
}
ASGI_APPLICATION = 'jumpserver.routing.application'
ASGI_APPLICATION = 'jumpserver.asgi.application'
# Dump all celery log to here
CELERY_LOG_DIR = os.path.join(PROJECT_DIR, 'data', 'celery')

Loading…
Cancel
Save