From 71943c0ab3d972fd8142555a07f8239c235d61da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Mon, 18 Mar 2024 11:42:05 +0100 Subject: [PATCH] chore: use asgi rather than wsgi By relying on Django Channels and Daphne. This requires a change in how the application is deployed to take that into account. --- pyproject.toml | 2 ++ umap/asgi.py | 16 ++++++++++++++++ umap/settings/base.py | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 umap/asgi.py diff --git a/pyproject.toml b/pyproject.toml index 177c5f0c..e36038b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,8 @@ classifiers = [ "Programming Language :: Python :: 3.12", ] dependencies = [ + "channels==4.0.0", + "daphne==4.1.0", "Django==5.1.1", "django-agnocomplete==2.2.0", "django-environ==0.11.2", diff --git a/umap/asgi.py b/umap/asgi.py new file mode 100644 index 00000000..00487a9c --- /dev/null +++ b/umap/asgi.py @@ -0,0 +1,16 @@ +import os + +from channels.routing import ProtocolTypeRouter +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "umap.settings") +# Initialize Django ASGI application early to ensure the AppRegistry +# is populated before importing code that may import ORM models. +django_asgi_app = get_asgi_application() + +application = ProtocolTypeRouter( + { + "http": django_asgi_app, + # Just HTTP for now. (We can add other protocols later.) + } +) diff --git a/umap/settings/base.py b/umap/settings/base.py index 73a1bf71..81131b9a 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -19,7 +19,7 @@ env = environ.Env() INTERNAL_IPS = env.list("INTERNAL_IPS", default=["127.0.0.1"]) ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=["*"]) ADMINS = tuple(parseaddr(email) for email in env.list("ADMINS", default=[])) - +ASGI_APPLICATION = "umap.asgi.application" DEBUG = env.bool("DEBUG", default=False) @@ -119,6 +119,7 @@ LANGUAGES = ( SECRET_KEY = env("SECRET_KEY", default=None) INSTALLED_APPS = ( + "daphne", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions",