From df3bb7135754298937225e66be4a95f9683ce105 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 4 Oct 2021 13:58:48 +0200 Subject: [PATCH] Serve static files with Nginx only in production to make JavaScript development easier Signed-off-by: Yohann D'ANELLO --- ansible/host_vars/bde-nk20-beta.adh.crans.org.yml | 6 ------ ansible/host_vars/bde-note-dev.adh.crans.org.yml | 1 + ansible/host_vars/bde-note.adh.crans.org.yml | 1 + ansible/hosts_example | 1 - ansible/roles/5-nginx/templates/nginx_note.conf | 2 ++ note_kfet/urls.py | 3 ++- 6 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 ansible/host_vars/bde-nk20-beta.adh.crans.org.yml diff --git a/ansible/host_vars/bde-nk20-beta.adh.crans.org.yml b/ansible/host_vars/bde-nk20-beta.adh.crans.org.yml deleted file mode 100644 index d9d850da..00000000 --- a/ansible/host_vars/bde-nk20-beta.adh.crans.org.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -note: - server_name: note-beta.crans.org - git_branch: beta - cron_enabled: false - email: notekfet2020@lists.crans.org diff --git a/ansible/host_vars/bde-note-dev.adh.crans.org.yml b/ansible/host_vars/bde-note-dev.adh.crans.org.yml index 471f35f0..8a4cdc43 100644 --- a/ansible/host_vars/bde-note-dev.adh.crans.org.yml +++ b/ansible/host_vars/bde-note-dev.adh.crans.org.yml @@ -2,5 +2,6 @@ note: server_name: note-dev.crans.org git_branch: beta + serve_static: false cron_enabled: false email: notekfet2020@lists.crans.org diff --git a/ansible/host_vars/bde-note.adh.crans.org.yml b/ansible/host_vars/bde-note.adh.crans.org.yml index 8405dc0f..9c8ec1ed 100644 --- a/ansible/host_vars/bde-note.adh.crans.org.yml +++ b/ansible/host_vars/bde-note.adh.crans.org.yml @@ -2,5 +2,6 @@ note: server_name: note.crans.org git_branch: master + serve_static: true cron_enabled: true email: notekfet2020@lists.crans.org diff --git a/ansible/hosts_example b/ansible/hosts_example index 79526d3d..bd83e3d2 100644 --- a/ansible/hosts_example +++ b/ansible/hosts_example @@ -1,6 +1,5 @@ [dev] bde-note-dev.adh.crans.org -bde-nk20-beta.adh.crans.org [prod] bde-note.adh.crans.org diff --git a/ansible/roles/5-nginx/templates/nginx_note.conf b/ansible/roles/5-nginx/templates/nginx_note.conf index 567c4789..02eb9056 100644 --- a/ansible/roles/5-nginx/templates/nginx_note.conf +++ b/ansible/roles/5-nginx/templates/nginx_note.conf @@ -41,6 +41,7 @@ server { # max upload size client_max_body_size 75M; # adjust to taste +{% if note.serve_static %} # Django media location /media { alias /var/www/note_kfet/media; # your Django project's media files - amend as required @@ -50,6 +51,7 @@ server { alias /var/www/note_kfet/static; # your Django project's static files - amend as required } +{% endif %} location /doc { alias /var/www/documentation; # The documentation of the project } diff --git a/note_kfet/urls.py b/note_kfet/urls.py index 9981df99..7fc37fa7 100644 --- a/note_kfet/urls.py +++ b/note_kfet/urls.py @@ -35,8 +35,9 @@ urlpatterns = [ path('coffee/', include('django_htcpcp_tea.urls')), ] -# During development, serve media files +# During development, serve static and media files if settings.DEBUG: + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if "oauth2_provider" in settings.INSTALLED_APPS: