From 9e9f07408d4d9210150484c348f406c3f3c4160a Mon Sep 17 00:00:00 2001 From: leviofanh Date: Thu, 18 Dec 2025 02:38:05 +0100 Subject: [PATCH] Added full support for the app-prefix parameter --- src/client.py | 3 ++- src/dashboard.py | 11 ++++++++--- src/static/app/index.html | 8 ++++++-- src/static/app/src/utilities/fetch.js | 7 +++++-- src/static/app/vite.config.js | 2 +- src/static/client/index.html | 10 +++++++--- src/static/client/src/utilities/request.js | 7 +++++-- src/static/client/vite.config.js | 2 +- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/client.py b/src/client.py index cc7ac218..67c84c9b 100644 --- a/src/client.py +++ b/src/client.py @@ -194,7 +194,8 @@ def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration], @client.get(prefix) def ClientIndex(): - return render_template('client.html') + app_prefix = dashboardConfig.GetConfig("Server", "app_prefix")[1] + return render_template('client.html', APP_PREFIX=app_prefix) @client.get(f'{prefix}/api/serverInformation') def ClientAPI_ServerInformation(): diff --git a/src/dashboard.py b/src/dashboard.py index ec57ef9d..76a719bf 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -72,7 +72,11 @@ def ResponseObject(status=True, message=None, data=None, status_code = 200) -> F ''' Flask App ''' -app = Flask("WGDashboard", template_folder=os.path.abspath("./static/dist/WGDashboardAdmin")) +_, APP_PREFIX_INIT = DashboardConfig().GetConfig("Server", "app_prefix") +app = Flask("WGDashboard", + template_folder=os.path.abspath("./static/dist/WGDashboardAdmin"), + static_folder=os.path.abspath("./static/dist/WGDashboardAdmin"), + static_url_path=APP_PREFIX_INIT if APP_PREFIX_INIT else '') def peerInformationBackgroundThread(): global WireguardConfigurations @@ -250,7 +254,8 @@ def auth_req(): '/static/', 'validateAuthentication', 'authenticate', 'getDashboardConfiguration', 'getDashboardTheme', 'getDashboardVersion', 'sharePeer/get', 'isTotpEnabled', 'locale', '/fileDownload', - '/client' + '/client', + '/assets/', '/img/', '/json/' ] if (("username" not in session or session.get("role") != "admin") @@ -1698,7 +1703,7 @@ Index Page @app.get(f'{APP_PREFIX}/') def index(): - return render_template('index.html') + return render_template('index.html', APP_PREFIX=APP_PREFIX) if __name__ == "__main__": startThreads() diff --git a/src/static/app/index.html b/src/static/app/index.html index 0c731866..7cfbd9e1 100644 --- a/src/static/app/index.html +++ b/src/static/app/index.html @@ -6,10 +6,14 @@ - - + + + WGDashboard +
diff --git a/src/static/app/src/utilities/fetch.js b/src/static/app/src/utilities/fetch.js index e9b7c8f4..a2c45f90 100644 --- a/src/static/app/src/utilities/fetch.js +++ b/src/static/app/src/utilities/fetch.js @@ -27,8 +27,11 @@ export const getUrl = (url) => { if (apiKey){ return `${apiKey.host}${url}` } - return import.meta.env.MODE === 'development' ? url - : `${window.location.protocol}//${(window.location.host + window.location.pathname + url).replace(/\/\//g, '/')}` + if (import.meta.env.MODE === 'development') { + return url; + } + const appPrefix = window.APP_PREFIX || ''; + return `${window.location.protocol}//${window.location.host}${appPrefix}${url}`; } export const fetchGet = async (url, params=undefined, callback=undefined) => { diff --git a/src/static/app/vite.config.js b/src/static/app/vite.config.js index 44fe8350..c5a8e887 100644 --- a/src/static/app/vite.config.js +++ b/src/static/app/vite.config.js @@ -32,7 +32,7 @@ export default defineConfig(({mode}) => { } return { - base: "/static/dist/WGDashboardAdmin", + base: "./", plugins: [ vue(), ], diff --git a/src/static/client/index.html b/src/static/client/index.html index 1f11e246..c58f6ee1 100644 --- a/src/static/client/index.html +++ b/src/static/client/index.html @@ -2,7 +2,8 @@ - + + WGDashboard Client +
- WGDashboard Client + WGDashboard Client
- + diff --git a/src/static/client/src/utilities/request.js b/src/static/client/src/utilities/request.js index 2e6eff88..cdccd980 100644 --- a/src/static/client/src/utilities/request.js +++ b/src/static/client/src/utilities/request.js @@ -2,8 +2,11 @@ import axios from "axios"; import {useRouter} from "vue-router"; export const requestURl = (url) => { - return import.meta.env.MODE === 'development' ? '/client' + url - : `${window.location.protocol}//${(window.location.host + window.location.pathname + url).replace(/\/\//g, '/')}` + if (import.meta.env.MODE === 'development') { + return '/client' + url; + } + const appPrefix = window.APP_PREFIX || ''; + return `${window.location.protocol}//${window.location.host}${appPrefix}/client${url}`; } // const router = useRouter() diff --git a/src/static/client/vite.config.js b/src/static/client/vite.config.js index 13543cec..091ca78e 100644 --- a/src/static/client/vite.config.js +++ b/src/static/client/vite.config.js @@ -40,5 +40,5 @@ export default defineConfig({ } } }, - base: '/static/dist/WGDashboardClient' + base: './' })