diff --git a/internal/router/router.go b/internal/router/router.go index 606c531..69458fd 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -246,10 +246,10 @@ func Setup(c *Controllers) *gin.Engine { html := string(data) - // 只注入配置变量,不做字符串替换 - // 前端会使用这些变量来构建正确的路径 - configScript := `` - html = strings.Replace(html, "", configScript+"", 1) + // 在第一个 script 标签中注入配置 + // 这样可以确保在资源加载前就设置好 base 标签 + configScript := `window.__BASE_URL__ = "` + urlPrefix + `"; window.__API_VERSION__ = "/api/v1";` + html = strings.Replace(html, "// 后端会在这里注入:", configScript + "\n //", 1) ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate") ctx.Data(200, "text/html; charset=utf-8", []byte(html)) diff --git a/web/index.html b/web/index.html index 1644274..c9497ac 100644 --- a/web/index.html +++ b/web/index.html @@ -2,20 +2,19 @@ + + -