root: fix websockets not working correctly
This commit is contained in:
		| @ -6,19 +6,21 @@ It exposes the ASGI callable as a module-level variable named ``application``. | ||||
| For more information on this file, see | ||||
| https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ | ||||
| """ | ||||
| import os | ||||
| import typing | ||||
| from time import time | ||||
| from typing import Any, ByteString, Dict | ||||
|  | ||||
| import django | ||||
| from asgiref.compatibility import guarantee_single_callable | ||||
| from channels.routing import ProtocolTypeRouter, URLRouter | ||||
| from defusedxml import defuse_stdlib | ||||
| from django.core.asgi import get_asgi_application | ||||
| from sentry_sdk.integrations.asgi import SentryAsgiMiddleware | ||||
| from structlog import get_logger | ||||
|  | ||||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.root.settings") | ||||
| from passbook.root import websocket | ||||
|  | ||||
| # DJANGO_SETTINGS_MODULE is set in gunicorn.conf.py | ||||
|  | ||||
| defuse_stdlib() | ||||
| django.setup() | ||||
| @ -129,5 +131,14 @@ class ASGILogger: | ||||
|  | ||||
|  | ||||
| application = ASGILogger( | ||||
|     guarantee_single_callable(SentryAsgiMiddleware(get_asgi_application())) | ||||
|     guarantee_single_callable( | ||||
|         SentryAsgiMiddleware( | ||||
|             ProtocolTypeRouter( | ||||
|                 { | ||||
|                     "http": get_asgi_application(), | ||||
|                     "websocket": URLRouter(websocket.websocket_urlpatterns), | ||||
|                 } | ||||
|             ) | ||||
|         ) | ||||
|     ) | ||||
| ) | ||||
|  | ||||
| @ -1,14 +0,0 @@ | ||||
| """root Websocket URLS""" | ||||
| from channels.routing import ProtocolTypeRouter, URLRouter | ||||
| from django.urls import path | ||||
|  | ||||
| from passbook.outposts.channels import OutpostConsumer | ||||
|  | ||||
| application = ProtocolTypeRouter( | ||||
|     { | ||||
|         # (http->django views is added by default) | ||||
|         "websocket": URLRouter( | ||||
|             [path("ws/outpost/<uuid:pk>/", OutpostConsumer.as_asgi())] | ||||
|         ), | ||||
|     } | ||||
| ) | ||||
| @ -208,7 +208,7 @@ TEMPLATES = [ | ||||
|     }, | ||||
| ] | ||||
|  | ||||
| ASGI_APPLICATION = "passbook.root.routing.application" | ||||
| ASGI_APPLICATION = "passbook.root.asgi.application" | ||||
|  | ||||
| CHANNEL_LAYERS = { | ||||
|     "default": { | ||||
|  | ||||
							
								
								
									
										6
									
								
								passbook/root/websocket.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								passbook/root/websocket.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| """root Websocket URLS""" | ||||
| from django.urls import path | ||||
|  | ||||
| from passbook.outposts.channels import OutpostConsumer | ||||
|  | ||||
| websocket_urlpatterns = [path("ws/outpost/<uuid:pk>/", OutpostConsumer.as_asgi())] | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer