Skip to content

Commit

Permalink
switch to asgi with Daphne
Browse files Browse the repository at this point in the history
  • Loading branch information
Neffi42 committed Aug 29, 2024
1 parent 319c60f commit 0509726
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions django/conf/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ echo "Collecting static files..."
python manage.py collectstatic --noinput
echo "Static files collected."

echo "Starting Gunicorn server with SSL..."
gunicorn --certfile=/ssl/${HOSTNAME}.crt --keyfile=/ssl/${HOSTNAME}.key ft_transcendence.wsgi:application --bind 0.0.0.0:443
echo "Starting Daphne server with SSL..."
daphne -e ssl:443:privateKey=/ssl/${HOSTNAME}.key:certKey=/ssl/${HOSTNAME}.crt ft_transcendence.asgi:application
7 changes: 6 additions & 1 deletion django/src/ft_transcendence/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

import os

from channels.routing import ProtocolTypeRouter
from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ft_transcendence.settings')

application = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": get_asgi_application(),
}
)
12 changes: 12 additions & 0 deletions django/src/ft_transcendence/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
# Application definition

INSTALLED_APPS = [
'daphne',
'channels',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -141,3 +143,13 @@
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}

ASGI_APPLICATION = 'ft_transcendence.asgi.application'
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("redis", 6379)],
},
},
}

0 comments on commit 0509726

Please sign in to comment.