Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix service worker script URL if app is not mounted in root of webserver #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pwa/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
# Get script prefix for apps not mounted under /
_PWA_SCRIPT_PREFIX = get_script_prefix()

# Path to the service worker script that will be registered
PWA_SERVICE_WORKER_SCRIPT_URL = _PWA_SCRIPT_PREFIX + 'serviceworker.js'

# Path to the manifest
PWA_MANIFEST_URL = _PWA_SCRIPT_PREFIX + 'manifest.json'

# Path to the service worker implementation. Default implementation is empty.
PWA_SERVICE_WORKER_PATH = getattr(settings, 'PWA_SERVICE_WORKER_PATH',
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates',
Expand Down
4 changes: 2 additions & 2 deletions pwa/templates/pwa.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Path to manifest.json -->
<link rel="manifest" href="/manifest.json">
<link rel="manifest" href="{{ PWA_MANIFEST_URL }}">

<!-- Add to homescreen for Chrome on Android -->
<meta name="mobile-web-app-capable" content="yes">
Expand Down Expand Up @@ -42,7 +42,7 @@
<script type="text/javascript">
// Initialize the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/serviceworker.js', {
navigator.serviceWorker.register('{{ PWA_SERVICE_WORKER_SCRIPT_URL }}', {
scope: '{{ PWA_APP_SCOPE }}'
}).then(function (registration) {
// Registration was successful
Expand Down