mirror of
https://github.com/h44z/wg-portal.git
synced 2026-06-15 14:28:14 +00:00
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 <richcarni@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1a541d7bd4
commit
012013c188
@@ -3,8 +3,8 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build-dev": "vite build --mode development --base=/app/",
|
"build-dev": "vite build --mode development",
|
||||||
"build": "vite build --base=/app/",
|
"build": "vite build",
|
||||||
"preview": "vite preview --port 5050"
|
"preview": "vite preview --port 5050"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import vue from '@vitejs/plugin-vue'
|
|||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
base: './',
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
@@ -283,10 +283,13 @@ func (s *Server) updateBasePathInFrontend(useEmbeddedFrontend bool) ([]byte, []b
|
|||||||
} else {
|
} else {
|
||||||
customIndexFile, _ = os.ReadFile(filepath.Join(s.cfg.Web.FrontendFilePath, "index.html"))
|
customIndexFile, _ = os.ReadFile(filepath.Join(s.cfg.Web.FrontendFilePath, "index.html"))
|
||||||
}
|
}
|
||||||
newIndexStr := strings.ReplaceAll(string(customIndexFile), "src=\"/", "src=\""+s.cfg.Web.BasePath+"/")
|
// rewrite relative paths
|
||||||
newIndexStr = strings.ReplaceAll(newIndexStr, "href=\"/", "href=\""+s.cfg.Web.BasePath+"/")
|
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)
|
match := re.FindStringSubmatch(newIndexStr)
|
||||||
cssFileName := match[1]
|
cssFileName := match[1]
|
||||||
|
|
||||||
@@ -296,7 +299,7 @@ func (s *Server) updateBasePathInFrontend(useEmbeddedFrontend bool) ([]byte, []b
|
|||||||
} else {
|
} else {
|
||||||
customCssFile, _ = os.ReadFile(filepath.Join(s.cfg.Web.FrontendFilePath, "/assets/", cssFileName))
|
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
|
return []byte(newIndexStr), []byte(newCssStr), cssFileName
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user