🎨 优化dockerfile,优化路由匹配

This commit is contained in:
2026-03-03 17:47:19 +08:00
parent 8e52b854ea
commit f8306be916
2 changed files with 17 additions and 7 deletions

View File

@@ -143,14 +143,21 @@ func setupFrontendRoutes(router *gin.Engine) {
// SPA 路由处理:所有非 API 请求都返回 index.html
router.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
// 如果是 API 请求,返回 404
if strings.HasPrefix(path, global.GVA_CONFIG.System.RouterPrefix) {
// 如果是 API 请求(/api/* 或 /v1/*),返回 404
routerPrefix := global.GVA_CONFIG.System.RouterPrefix
if routerPrefix == "" {
routerPrefix = "/api"
}
if strings.HasPrefix(path, routerPrefix) || strings.HasPrefix(path, "/v1") {
c.JSON(http.StatusNotFound, gin.H{
"code": 404,
"msg": "接口不存在",
})
return
}
// 其他请求返回前端页面
c.File("./dist/index.html")
})