Try to be less dumb about insecure hosting

This commit is contained in:
Timothy Farrell 2018-01-18 14:22:34 -06:00
parent 448111b8b8
commit 9684a82327

View File

@ -16,7 +16,13 @@ function go() {
router.start('home');
}
if ('serviceWorker' in navigator && window.top === window) {
const url = `https://${location.host}${location.pathname}${location.hash}`;
const msg = `This photo gallery will not work properly unless accessed securely. Connect to ${url} instead?`;
// We use subtleCrypto which is only available from secure domains and localhost.
if (location.protocol !== 'https:' && (!crypto.subtle || !crypto.subtle.digest) && confirm(msg)) {
location.assign(url);
} else if ('serviceWorker' in navigator && window.top === window) {
navigator.serviceWorker
.register('/assets/sw.bundle.js', { scope: '/' })
.then(go)