fix: url prefix page redirect

This commit is contained in:
engigu
2026-01-13 21:52:49 +08:00
parent 460a6c9d8a
commit 23d947cb92
2 changed files with 20 additions and 1 deletions
+9 -1
View File
@@ -243,8 +243,16 @@ func Setup(c *Controllers) *gin.Engine {
ctx.String(500, "index.html not found")
return
}
html := string(data)
// 只注入配置变量,不做字符串替换
// 前端会使用这些变量来构建正确的路径
configScript := `<script>window.__BASE_URL__ = "` + urlPrefix + `"; window.__API_VERSION__ = "/api/v1";</script>`
html = strings.Replace(html, "</head>", configScript+"</head>", 1)
ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
ctx.Data(200, "text/html; charset=utf-8", data)
ctx.Data(200, "text/html; charset=utf-8", []byte(html))
})
return router