From 4caf1add26a338cdd19edd0afb4e4d1de8870d1e Mon Sep 17 00:00:00 2001 From: Karl Date: Thu, 17 Jul 2025 16:43:07 +0100 Subject: [PATCH] send over https --- templates/base.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/templates/base.html b/templates/base.html index aed1bd0..cdd96ec 100644 --- a/templates/base.html +++ b/templates/base.html @@ -74,7 +74,10 @@ } function subscribeUser(registration) { - const baseUrl = '{{ config.BASE_URL }}'.replace(/\/$/, ""); // Remove trailing slash if present + 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()) .then(data => { @@ -88,11 +91,16 @@ }).catch(function(err) { console.log('Failed to subscribe the user: ', err); }); + }).catch(function(err) { + console.error('Failed to fetch vapid key:', err); }); } function saveSubscription(subscription) { - const baseUrl = '{{ config.BASE_URL }}'.replace(/\/$/, ""); // Remove trailing slash if present + 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`, { method: 'POST', headers: {