]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
feat(pwa): enhance connectivity checks
authorPierre <397503+bemble@users.noreply.github.com>
Mon, 9 May 2022 21:47:05 +0000 (23:47 +0200)
committerPierre <397503+bemble@users.noreply.github.com>
Mon, 9 May 2022 21:47:05 +0000 (23:47 +0200)
Also add support to auth proxy such as Authelia

src/components/ConnectivityChecker.vue
vue.config.js

index 02cbd7fcd4c45d58888cc8f99bb88e00661c18c3..a717bcf0389fa3bf5667f119102d2f91475dc09b 100644 (file)
@@ -29,15 +29,40 @@ export default {
       },
       false
     );
+    window.addEventListener(
+      "online",
+      function () {
+          that.checkOffline();
+      },
+      false
+    );
+    window.addEventListener(
+      "offline",
+      function () {
+        this.offline = true;
+      },
+      false
+    );
   },
   methods: {
     checkOffline: function () {
+      if (!navigator.onLine) {
+        this.offline = true;
+        return;
+      }
+
+      // extra check to make sure we're not offline
       let that = this;
       return fetch(window.location.href + "?alive", {
         method: "HEAD",
         cache: "no-store",
+        redirect: "manual"
       })
         .then(function (response) {
+          // opaqueredirect means request has been redirected, to auth provider probably
+          if (response.type === "opaqueredirect" && !response.ok) {
+            window.location.reload(true);
+          }
           that.offline = !response.ok;
         })
         .catch(function () {
index 410acc89ce30a0cd6bccd1bdd8dda871fd9c8978..1645c2f83e112bfd3cef7e18b5b1e030621727c2 100644 (file)
@@ -26,4 +26,7 @@ module.exports = {
       msTileImage: "assets/icons/icon-any.png",
     },
   },
+  devServer: {
+    disableHostCheck: true
+  },
 };