From b95f00486b2640a211b6862f148c78a68cf593cd Mon Sep 17 00:00:00 2001 From: Karl Date: Thu, 17 Jul 2025 16:50:08 +0100 Subject: [PATCH] relative path --- templates/base.html | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/templates/base.html b/templates/base.html index cdd96ec..33142e7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -74,12 +74,13 @@ } function subscribeUser(registration) { - let baseUrl = '{{ config.BASE_URL }}'.replace(/\/$/, ""); // Remove trailing slash if present - if (window.location.protocol === 'https:') { - baseUrl = baseUrl.replace(/^http:/, 'https:'); - } - fetch(`${baseUrl}/vapid-public-key`) - .then(response => response.json()) + fetch('/vapid-public-key') + .then(response => { + if (!response.ok) { + throw new Error('Failed to fetch VAPID public key'); + } + return response.json(); + }) .then(data => { const applicationServerKey = urlB64ToUint8Array(data.public_key); registration.pushManager.subscribe({ @@ -92,16 +93,12 @@ console.log('Failed to subscribe the user: ', err); }); }).catch(function(err) { - console.error('Failed to fetch vapid key:', err); + console.error('Error during subscription process:', err); }); } function saveSubscription(subscription) { - let baseUrl = '{{ config.BASE_URL }}'.replace(/\/$/, ""); // Remove trailing slash if present - if (window.location.protocol === 'https:') { - baseUrl = baseUrl.replace(/^http:/, 'https:'); - } - fetch(`${baseUrl}/save-subscription`, { + fetch('/save-subscription', { method: 'POST', headers: { 'Content-Type': 'application/json',