diff --git a/api/config/settings/common.py b/api/config/settings/common.py index f5ddec00b1da2f591f1a651e1b9c60427d1f4da1..e5389756f473c8d61aeb17576cb923d1c8b38849 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -30,6 +30,7 @@ ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS') # APP CONFIGURATION # ------------------------------------------------------------------------------ DJANGO_APPS = ( + 'channels', # Default Django apps: 'django.contrib.auth', 'django.contrib.contenttypes', @@ -253,9 +254,9 @@ MEDIA_URL = env("MEDIA_URL", default='/media/') # URL Configuration # ------------------------------------------------------------------------------ ROOT_URLCONF = 'config.urls' - # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application WSGI_APPLICATION = 'config.wsgi.application' +ASGI_APPLICATION = "config.routing.application" # AUTHENTICATION CONFIGURATION # ------------------------------------------------------------------------------ @@ -284,6 +285,17 @@ CACHES = { } CACHES["default"]["BACKEND"] = "django_redis.cache.RedisCache" +from urllib.parse import urlparse +cache_url = urlparse(CACHES['default']['LOCATION']) +CHANNEL_LAYERS = { + "default": { + "BACKEND": "channels_redis.core.RedisChannelLayer", + "CONFIG": { + "hosts": [(cache_url.hostname, cache_url.port)], + }, + }, +} + CACHES["default"]["OPTIONS"] = { "CLIENT_CLASS": "django_redis.client.DefaultClient", "IGNORE_EXCEPTIONS": True, # mimics memcache behavior. diff --git a/api/requirements/base.txt b/api/requirements/base.txt index 133fcc0cb65f0deb430d73ff5259d05efc215cc2..d402d359137126ae87bb255aa091ca548a61a681 100644 --- a/api/requirements/base.txt +++ b/api/requirements/base.txt @@ -59,3 +59,5 @@ pyacoustid>=1.1.5,<1.2 raven>=6.5,<7 python-magic==0.4.15 ffmpeg-python==0.1.10 +channels>=2,<2.1 +channels_redis>=2.1,<2.2 diff --git a/docker/nginx/conf.dev b/docker/nginx/conf.dev index 29c04fc6643c17a8918c9ad4546993d49587336e..9847c2dcbcc71bf3040802d6289c7336ff40c340 100644 --- a/docker/nginx/conf.dev +++ b/docker/nginx/conf.dev @@ -28,6 +28,11 @@ http { #gzip on; proxy_cache_path /tmp/funkwhale-transcode levels=1:2 keys_zone=transcode:10m max_size=1g inactive=24h use_temp_path=off; + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + server { listen 6001; charset utf-8; @@ -40,6 +45,9 @@ http { proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host localhost:8080; proxy_set_header X-Forwarded-Port 8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; proxy_redirect off; location /_protected/media { diff --git a/front/config/index.js b/front/config/index.js index 7ce6e26e1c63ad12fc681a5317158856d30a99c8..14cbe3e4388ea6a5e18a6053a1611ffd0cd6ab38 100644 --- a/front/config/index.js +++ b/front/config/index.js @@ -32,6 +32,7 @@ module.exports = { '/api': { target: 'http://nginx:6001', changeOrigin: true, + ws: true }, '/media': { target: 'http://nginx:6001', diff --git a/front/package.json b/front/package.json index d6bdb8c56caaeb8da80213800537ed255b5c960a..201694e43648e08c6bd23b2fa869ca83c29c7e2d 100644 --- a/front/package.json +++ b/front/package.json @@ -17,6 +17,7 @@ "dependencies": { "axios": "^0.17.1", "dateformat": "^2.0.0", + "django-channels": "^1.1.6", "js-logger": "^1.3.0", "jwt-decode": "^2.2.0", "lodash": "^4.17.4",