From 763c2164a1cf9adafdbbd96b280aef7e5d665b90 Mon Sep 17 00:00:00 2001 From: Sebastian Vansteenkiste Date: Tue, 23 Jul 2019 11:31:46 -0300 Subject: [PATCH] Serving PWA-related files --- home/settings/base.py | 2 +- home/urls.py | 19 ++++++++++++++++++ {public => non_generated_static}/favicon.ico | Bin .../manifest.json | 0 public/index.html | 5 +++-- 5 files changed, 23 insertions(+), 3 deletions(-) rename {public => non_generated_static}/favicon.ico (100%) rename {public => non_generated_static}/manifest.json (100%) diff --git a/home/settings/base.py b/home/settings/base.py index a2dd6687..c9a8d36c 100644 --- a/home/settings/base.py +++ b/home/settings/base.py @@ -61,7 +61,7 @@ STATIC_URL = '/static/' MEDIA_URL = '/media/' -STATICFILES_DIRS = [os.path.join(BASE_DIR, 'build/static')] +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'build/static'), os.path.join(BASE_DIR, 'non_generated_static')] STATIC_ROOT = os.path.join(BASE_DIR, 'static') MEDIA_ROOT = os.path.join(BASE_DIR, 'media') SITE_ID = 1 diff --git a/home/urls.py b/home/urls.py index 52573fb9..cd83339c 100644 --- a/home/urls.py +++ b/home/urls.py @@ -1,8 +1,27 @@ from django.contrib import admin from django.urls import path, include, re_path from django.views.generic import TemplateView +from django.conf import settings +import os + + +# The precache-manifest may be generated with a new name, so we need to get it manually +files_in_root = [] +for file in os.listdir(os.path.join(settings.BASE_DIR, 'build')): + files_in_root.append(file) +precache_manifest_path = [f for f in files_in_root if ("precache-manifest" in f)][0] urlpatterns = [ + path('asset-manifest.json', (TemplateView.as_view(template_name="asset-manifest.json", + content_type='application/manifest+json', )), + name='asset-manifest.json'), + path('service-worker.js', (TemplateView.as_view(template_name="service-worker.js", + content_type='application/javascript', )), + name='service-worker.js'), + path(precache_manifest_path, ( + TemplateView.as_view(template_name=precache_manifest_path, + content_type='application/javascript', )), + name=precache_manifest_path), path('api-auth/', include('rest_framework.urls')), path('rest-auth/', include('rest_auth.urls')), path('rest-auth/registration/', include('rest_auth.registration.urls')), diff --git a/public/favicon.ico b/non_generated_static/favicon.ico similarity index 100% rename from public/favicon.ico rename to non_generated_static/favicon.ico diff --git a/public/manifest.json b/non_generated_static/manifest.json similarity index 100% rename from public/manifest.json rename to non_generated_static/manifest.json diff --git a/public/index.html b/public/index.html index 6497ed56..b9cf9abf 100644 --- a/public/index.html +++ b/public/index.html @@ -1,11 +1,12 @@ +{% load static %} - - + + Django React Boilerplate