aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBastien Wirtz <bastien.wirtz@gmail.com>2022-06-04 09:07:15 +0200
committerGitHub <noreply@github.com>2022-06-04 09:07:15 +0200
commit2b48d1c057bf24776fb0538c7db0a0b156e667c5 (patch)
tree47a6b64226c3d3707b285a6de3838a2d7270b59f
parent95d73348e5dd8fd0fbb1b6747c58b346ecf772ad (diff)
parent95249e11255beb8b85f904c54429b353fca40b9e (diff)
downloadhomer-2b48d1c057bf24776fb0538c7db0a0b156e667c5.tar.gz
homer-2b48d1c057bf24776fb0538c7db0a0b156e667c5.tar.zst
homer-2b48d1c057bf24776fb0538c7db0a0b156e667c5.zip
Merge pull request #448 from bemble/main
feat(pwa): enhance connectivity checks
-rw-r--r--docs/configuration.md3
-rw-r--r--docs/troubleshooting.md6
-rw-r--r--src/App.vue8
-rw-r--r--src/components/ConnectivityChecker.vue31
-rw-r--r--vue.config.js3
5 files changed, 42 insertions, 9 deletions
diff --git a/docs/configuration.md b/docs/configuration.md
index bb41948..a4da08b 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -25,7 +25,8 @@ header: true # Set to false to hide the header
25footer: '<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. 25footer: '<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.
26 26
27columns: "3" # "auto" or number (must be a factor of 12: 1, 2, 3, 4, 6, 12) 27columns: "3" # "auto" or number (must be a factor of 12: 1, 2, 3, 4, 6, 12)
28connectivityCheck: true # whether you want to display a message when the apps are not accessible anymore (VPN disconnected for example) 28connectivityCheck: true # whether you want to display a message when the apps are not accessible anymore (VPN disconnected for example).
29 # You should set it to true when using an authentication proxy, it also reloads the page when a redirection is detected when checking connectivity.
29 30
30# Optional: Proxy / hosting option 31# Optional: Proxy / hosting option
31proxy: 32proxy:
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 649e5a6..10d6c2d 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -17,3 +17,9 @@ To resolve this, you can either:
17* Host all your target service under the same domain & port. 17* Host all your target service under the same domain & port.
18* 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. 18* 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.
19* 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. 19* 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.
20
21## I am using an authentication proxy and homer says I am offline
22
23This should be a configuration issue.
24* Make sure the option `connectivityCheck` is set to `true` in configuration.
25* Check your proxy configuration, the expected behavior is to redirect user using a 302 to the login page when user is not authenticated.
diff --git a/src/App.vue b/src/App.vue
index c58fca1..664867f 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -231,13 +231,7 @@ export default {
231 }, 231 },
232 getConfig: function (path = "assets/config.yml") { 232 getConfig: function (path = "assets/config.yml") {
233 return fetch(path).then((response) => { 233 return fetch(path).then((response) => {
234 if (response.redirected) { 234 if (response.status == 404 || response.redirected) {
235 // This allows to work with authentication proxies.
236 window.location.href = response.url;
237 return;
238 }
239
240 if (response.status == 404) {
241 this.configNotFound = true; 235 this.configNotFound = true;
242 return {}; 236 return {};
243 } 237 }
diff --git a/src/components/ConnectivityChecker.vue b/src/components/ConnectivityChecker.vue
index 02cbd7f..f2be652 100644
--- a/src/components/ConnectivityChecker.vue
+++ b/src/components/ConnectivityChecker.vue
@@ -17,6 +17,9 @@ export default {
17 }; 17 };
18 }, 18 },
19 created: function () { 19 created: function () {
20 if (/t=\d+/.test(window.location.href)) {
21 window.history.replaceState({}, document.title, window.location.pathname);
22 }
20 let that = this; 23 let that = this;
21 this.checkOffline(); 24 this.checkOffline();
22 25
@@ -29,15 +32,41 @@ export default {
29 }, 32 },
30 false 33 false
31 ); 34 );
35 window.addEventListener(
36 "online",
37 function () {
38 that.checkOffline();
39 },
40 false
41 );
42 window.addEventListener(
43 "offline",
44 function () {
45 this.offline = true;
46 },
47 false
48 );
32 }, 49 },
33 methods: { 50 methods: {
34 checkOffline: function () { 51 checkOffline: function () {
52 if (!navigator.onLine) {
53 this.offline = true;
54 return;
55 }
56
57 // extra check to make sure we're not offline
35 let that = this; 58 let that = this;
36 return fetch(window.location.href + "?alive", { 59 const aliveCheckUrl = window.location.href + "?t="+(new Date().valueOf());
60 return fetch(aliveCheckUrl, {
37 method: "HEAD", 61 method: "HEAD",
38 cache: "no-store", 62 cache: "no-store",
63 redirect: "manual"
39 }) 64 })
40 .then(function (response) { 65 .then(function (response) {
66 // opaqueredirect means request has been redirected, to auth provider probably
67 if ((response.type === "opaqueredirect" && !response.ok) || [401, 403].indexOf(response.status) != -1) {
68 window.location.href = aliveCheckUrl;
69 }
41 that.offline = !response.ok; 70 that.offline = !response.ok;
42 }) 71 })
43 .catch(function () { 72 .catch(function () {
diff --git a/vue.config.js b/vue.config.js
index 410acc8..1645c2f 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -26,4 +26,7 @@ module.exports = {
26 msTileImage: "assets/icons/icon-any.png", 26 msTileImage: "assets/icons/icon-any.png",
27 }, 27 },
28 }, 28 },
29 devServer: {
30 disableHostCheck: true
31 },
29}; 32};