]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Merge pull request #448 from bemble/main
authorBastien Wirtz <bastien.wirtz@gmail.com>
Sat, 4 Jun 2022 07:07:15 +0000 (09:07 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Jun 2022 07:07:15 +0000 (09:07 +0200)
feat(pwa): enhance connectivity checks

docs/configuration.md
docs/troubleshooting.md
src/App.vue
src/components/ConnectivityChecker.vue
vue.config.js

index bb4194899d098290bb9fbdacc755f6a87e5057a3..a4da08bd56617d58182916b50c21353e24661a3d 100644 (file)
@@ -25,7 +25,8 @@ header: true # Set to false to hide the header
 footer: '<p>Created with <span class="has-text-danger">❤️</span> with <a href="https://bulma.io/">bulma</a>, <a href="https://vuejs.org/">vuejs</a> & <a href="https://fontawesome.com/">font awesome</a> // Fork me on <a href="https://github.com/bastienwirtz/homer"><i class="fab fa-github-alt"></i></a></p>' # set false if you want to hide it.
 
 columns: "3" # "auto" or number (must be a factor of 12: 1, 2, 3, 4, 6, 12)
-connectivityCheck: true # whether you want to display a message when the apps are not accessible anymore (VPN disconnected for example)
+connectivityCheck: true # whether you want to display a message when the apps are not accessible anymore (VPN disconnected for example).
+                        # You should set it to true when using an authentication proxy, it also reloads the page when a redirection is detected when checking connectivity.
 
 # Optional: Proxy / hosting option
 proxy:
index 649e5a61fc959d437e0a47ccd1c14dc159798b8c..10d6c2ddd63f782eaad1372e752f117b97d9f624 100644 (file)
@@ -17,3 +17,9 @@ To resolve this, you can either:
 * Host all your target service under the same domain & port.
 * Modify the target server configuration so that the response of the server included following header- `Access-Control-Allow-Origin: *` (<https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests>). It might be an option in the targeted service, otherwise depending on how the service is hosted, the proxy or web server can seamlessly add it.
 * Use a cors proxy server like [`cors-container`](https://github.com/imjacobclark/cors-container), [`cors-anywhere`](https://github.com/Rob--W/cors-anywhere) or many others.
+
+## I am using an authentication proxy and homer says I am offline
+
+This should be a configuration issue.
+* Make sure the option `connectivityCheck` is set to `true` in configuration.
+* Check your proxy configuration, the expected behavior is to redirect user using a 302 to the login page when user is not authenticated.
index c58fca1096726f8f8d13196def444547b983dccb..664867f219a24a3d71346d49ada44219149d6ef3 100644 (file)
@@ -231,13 +231,7 @@ export default {
     },
     getConfig: function (path = "assets/config.yml") {
       return fetch(path).then((response) => {
-        if (response.redirected) {
-          // This allows to work with authentication proxies.
-          window.location.href = response.url;
-          return;
-        }
-
-        if (response.status == 404) {
+        if (response.status == 404 || response.redirected) {
           this.configNotFound = true;
           return {};
         }
index 02cbd7fcd4c45d58888cc8f99bb88e00661c18c3..f2be6523c18822d586a5917a2b14ee3d092c2186 100644 (file)
@@ -17,6 +17,9 @@ export default {
     };
   },
   created: function () {
+    if (/t=\d+/.test(window.location.href)) {
+      window.history.replaceState({}, document.title, window.location.pathname);
+    }
     let that = this;
     this.checkOffline();
 
@@ -29,15 +32,41 @@ 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", {
+      const aliveCheckUrl = window.location.href + "?t="+(new Date().valueOf());
+      return fetch(aliveCheckUrl, {
         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) || [401, 403].indexOf(response.status) != -1) {
+            window.location.href = aliveCheckUrl;
+          }
           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
+  },
 };