From 99b1a841c552d072a541e133557d027199002ae3 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Thu, 7 Aug 2025 12:30:28 +0200 Subject: [PATCH] Let the user know when using a remote frontend. Note: this relies on the gateway Nginx server configurations including an X-Dougal-Server header, as follows: add_header X-Dougal-Server "remote-frontend" always; --- .../client/source/src/components/footer.vue | 15 +++++++++++--- .../source/src/store/modules/api/actions.js | 20 +++++++++++++++++++ .../source/src/store/modules/api/state.js | 3 ++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/www/client/source/src/components/footer.vue b/lib/www/client/source/src/components/footer.vue index e2fc699..93d806a 100644 --- a/lib/www/client/source/src/components/footer.vue +++ b/lib/www/client/source/src/components/footer.vue @@ -9,8 +9,14 @@ - mdi-lan-connect - mdi-lan-disconnect + + @@ -57,7 +63,10 @@ export default { return date.getUTCFullYear(); }, - ...mapState({serverConnected: state => state.notify.serverConnected}) + ...mapState({ + serverConnected: state => state.notify.serverConnected, + isFrontendRemote: state => state.api.serverInfo?.["remote-frontend"] ?? false + }) } }; diff --git a/lib/www/client/source/src/store/modules/api/actions.js b/lib/www/client/source/src/store/modules/api/actions.js index b291805..4fbe17d 100644 --- a/lib/www/client/source/src/store/modules/api/actions.js +++ b/lib/www/client/source/src/store/modules/api/actions.js @@ -79,6 +79,26 @@ async function api ({state, getters, commit, dispatch}, [resource, init = {}, cb await cb(null, res.clone()); } + if (res.headers.has("x-dougal-server")) { + const header = res.headers.get("x-dougal-server") + const entries = header + .split(";") + .map(part => part.trim()) + .filter(part => part.length > 0) + .map(part => { + const idx = part.indexOf('='); + if (idx === -1) { + return [part, true]; + } + const key = part.slice(0, idx).trim(); + const value = part.slice(idx + 1).trim(); + return [key, value]; + }); + state.serverInfo = entries.length ? Object.fromEntries(entries) : {}; + console.log("ENTRIES", entries); + console.log("SERVER INFO", state.serverInfo); + } + if (res.ok) { if (!isCached) { diff --git a/lib/www/client/source/src/store/modules/api/state.js b/lib/www/client/source/src/store/modules/api/state.js index ba5c8bc..c12faee 100644 --- a/lib/www/client/source/src/store/modules/api/state.js +++ b/lib/www/client/source/src/store/modules/api/state.js @@ -1,7 +1,8 @@ const state = () => ({ apiUrl: "/api", requestsCount: 0, - maxConcurrent: 15 + maxConcurrent: 15, + serverInfo: {} // Contents of the last received X-Dougal-Server HTTP header }); export default state;