-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further update Daphne/Channels for v4
- Move routing to asgi.py per Django convention - Use Consumer.as_asgi() for ASGI 3 compatibility - Use the new Daphne application server
- Loading branch information
1 parent
6a5a1fc
commit e889337
Showing
5 changed files
with
48 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
""" | ||
ASGI config for tin 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/4.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
from typing import Optional | ||
|
||
from channels.routing import get_default_application | ||
from channels.auth import AuthMiddlewareStack | ||
from channels.generic.websocket import WebsocketConsumer | ||
from channels.routing import ProtocolTypeRouter, URLRouter | ||
|
||
import django | ||
from django.core.asgi import get_asgi_application | ||
from django.urls import path | ||
|
||
from .apps.submissions.consumers import SubmissionJsonConsumer | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tin.settings") | ||
django.setup() | ||
application = get_default_application() | ||
|
||
|
||
class WebsocketCloseConsumer(WebsocketConsumer): | ||
def connect(self): | ||
self.accept() | ||
self.close() | ||
|
||
def receive(self, text_data: Optional[str] = None, bytes_data: Optional[bytes] = None): | ||
pass | ||
|
||
def disconnect(self, code): | ||
pass | ||
|
||
|
||
application = ProtocolTypeRouter( | ||
{ | ||
"http": get_asgi_application(), | ||
"websocket": AuthMiddlewareStack( | ||
URLRouter( | ||
[ | ||
path("submissions/<int:submission_id>.json", SubmissionJsonConsumer.as_asgi()), | ||
path("<path:path>", WebsocketCloseConsumer.as_asgi()), | ||
] | ||
) | ||
), | ||
} | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters