diff --git a/requirements.txt b/requirements.txt index f301200..46ca335 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ install==1.3.5 pytz==2023.3.post1 sqlparse==0.4.4 channels==3.0.5 +daphne diff --git a/trancendence/asgi.py b/trancendence/asgi.py index eaaad8a..5608a42 100644 --- a/trancendence/asgi.py +++ b/trancendence/asgi.py @@ -8,9 +8,20 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ """ import os +from channels.routing import ProtocolTypeRouter, URLRouter +from channels.auth import AuthMiddlewareStack +import frontend.routing from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings') -application = get_asgi_application() +application = ProtocolTypeRouter({ + 'http':get_asgi_application(), + 'websocket':AuthMiddlewareStack( + URLRouter( + frontend.routing.websocket_urlpatterns + ) + ) +}) + diff --git a/trancendence/settings.py b/trancendence/settings.py index a8d3760..2c57c6a 100644 --- a/trancendence/settings.py +++ b/trancendence/settings.py @@ -38,6 +38,9 @@ CORS_ORIGIN_WHITELIST = ( # Application definition INSTALLED_APPS = [ + 'channels', + 'daphne', + 'accounts.apps.AccountsConfig', 'profiles.apps.ProfilesConfig', 'frontend.apps.FrontendConfig', @@ -52,6 +55,14 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', ] +ASGI_APPLICATION = 'trancendence.asgi.application' + +CHANNEL_LAYERS = { + 'default' :{ + 'BACKEND':'channels.layers.InMemoryChannelLayer' + } +} + MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware',