feat: websockets
This commit is contained in:
+16
-1
@@ -4,4 +4,19 @@ from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
# get_asgi_application() llama a django.setup(): tiene que ejecutarse antes de
|
||||
# importar routing/consumers, porque estos importan modelos.
|
||||
django_asgi_app = get_asgi_application()
|
||||
|
||||
from channels.auth import AuthMiddlewareStack # noqa: E402
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter # noqa: E402
|
||||
from channels.security.websocket import AllowedHostsOriginValidator # noqa: E402
|
||||
|
||||
from backoffice.routing import websocket_urlpatterns # noqa: E402
|
||||
|
||||
application = ProtocolTypeRouter(
|
||||
{
|
||||
'http': django_asgi_app,
|
||||
'websocket': AllowedHostsOriginValidator(AuthMiddlewareStack(URLRouter(websocket_urlpatterns))),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -23,6 +23,7 @@ if not DEBUG:
|
||||
|
||||
|
||||
DJANGO_APPS = [
|
||||
'daphne', # antes de staticfiles: hace que runserver sirva HTTP y WS
|
||||
'unfold', # before django.contrib.admin
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
@@ -33,6 +34,7 @@ DJANGO_APPS = [
|
||||
]
|
||||
|
||||
THIRD_PARTY_APPS = [
|
||||
'channels',
|
||||
'corsheaders',
|
||||
'django_extensions',
|
||||
'django_filters',
|
||||
@@ -88,6 +90,16 @@ TEMPLATES = [
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'config.wsgi.application'
|
||||
ASGI_APPLICATION = 'config.asgi.application'
|
||||
|
||||
# Channels usa el mismo Redis que ya sirve de broker de Celery (ver
|
||||
# REDIS_HOST/REDIS_PORT en config/settings/environ.py).
|
||||
CHANNEL_LAYERS = {
|
||||
'default': {
|
||||
'BACKEND': 'channels_redis.core.RedisChannelLayer',
|
||||
'CONFIG': {'hosts': [(REDIS_HOST, int(REDIS_PORT))]},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Database
|
||||
|
||||
Reference in New Issue
Block a user