-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathasgi.py
38 lines (28 loc) · 1.17 KB
/
asgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
ASGI config for Conreq 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/3.0/howto/deployment/asgi/
"""
import os
from django.conf.urls import url
from django.core.asgi import get_asgi_application
# Fetch Django ASGI application early to ensure AppRegistry is populated
# before importing consumers and AuthMiddlewareStack that may import ORM
# models.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "conreq.settings")
django_asgi_app = get_asgi_application()
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from conreq.core.server_websockets import CommandConsumer
application = ProtocolTypeRouter(
{
# Cannot use asgi app due to concurrency problems, currently using wsgi to serve http
# See https://github.com/django/channels/issues/1587
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter([url("", CommandConsumer().as_asgi())]))
),
}
)