From 012013c18840e4cf184987d66ee306f4eaf09b48 Mon Sep 17 00:00:00 2001 From: Richard Carnibella <42241043+richcarni@users.noreply.github.com> Date: Tue, 9 Jun 2026 04:08:41 +1000 Subject: [PATCH] Fix vue assets under web base path (#711) Remove hardcoded `--base=/app/` from npm build script and set `base: './'` in vite.config to generate relative asset URLs Update server `updateBasePathInFrontend` to handle relative paths Fixes #710 Signed-off-by: Rich C --- frontend/package.json | 4 ++-- frontend/vite.config.mjs | 1 + internal/app/api/core/server.go | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index e0396d3..bd5d982 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,8 +3,8 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build-dev": "vite build --mode development --base=/app/", - "build": "vite build --base=/app/", + "build-dev": "vite build --mode development", + "build": "vite build", "preview": "vite preview --port 5050" }, "dependencies": { diff --git a/frontend/vite.config.mjs b/frontend/vite.config.mjs index b9bb9d1..e0670af 100644 --- a/frontend/vite.config.mjs +++ b/frontend/vite.config.mjs @@ -5,6 +5,7 @@ import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ + base: './', plugins: [vue()], resolve: { alias: { diff --git a/internal/app/api/core/server.go b/internal/app/api/core/server.go index 6b82ed8..b0a8924 100644 --- a/internal/app/api/core/server.go +++ b/internal/app/api/core/server.go @@ -283,10 +283,13 @@ func (s *Server) updateBasePathInFrontend(useEmbeddedFrontend bool) ([]byte, []b } else { customIndexFile, _ = os.ReadFile(filepath.Join(s.cfg.Web.FrontendFilePath, "index.html")) } - newIndexStr := strings.ReplaceAll(string(customIndexFile), "src=\"/", "src=\""+s.cfg.Web.BasePath+"/") - newIndexStr = strings.ReplaceAll(newIndexStr, "href=\"/", "href=\""+s.cfg.Web.BasePath+"/") + // rewrite relative paths + newIndexStr := strings.ReplaceAll(string(customIndexFile), "src=\"./", "src=\""+s.cfg.Web.BasePath+"/app/") + newIndexStr = strings.ReplaceAll(newIndexStr, "href=\"./", "href=\""+s.cfg.Web.BasePath+"/app/") + // rewrite absolute paths (api calls) + newIndexStr = strings.ReplaceAll(newIndexStr, "src=\"/api/", "src=\""+s.cfg.Web.BasePath+"/api/") - re := regexp.MustCompile(`/app/assets/(index-.+.css)`) + re := regexp.MustCompile(`assets/(index-.+.css)`) match := re.FindStringSubmatch(newIndexStr) cssFileName := match[1] @@ -296,7 +299,7 @@ func (s *Server) updateBasePathInFrontend(useEmbeddedFrontend bool) ([]byte, []b } else { customCssFile, _ = os.ReadFile(filepath.Join(s.cfg.Web.FrontendFilePath, "/assets/", cssFileName)) } - newCssStr := strings.ReplaceAll(string(customCssFile), "/app/assets/", s.cfg.Web.BasePath+"/app/assets/") + newCssStr := strings.ReplaceAll(string(customCssFile), "./assets/", s.cfg.Web.BasePath+"/app/assets/") return []byte(newIndexStr), []byte(newCssStr), cssFileName }