新增几大中心功能

This commit is contained in:
Administrator
2026-04-23 15:29:07 +08:00
parent 5c2a146a44
commit c6354ee065
123 changed files with 13074 additions and 229 deletions

View File

@@ -18,11 +18,11 @@ func Cors() gin.HandlerFunc {
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type, New-Token, New-Expires-At")
c.Header("Access-Control-Allow-Credentials", "true")
// 放行所有OPTIONS方法
// 放行所有OPTIONS方法(预检请求不应继续进入路由,否则易落到 404
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
// 处理请求
c.Next()
}
}
@@ -50,14 +50,14 @@ func CorsByRules() gin.HandlerFunc {
// 严格白名单模式且未通过检查,直接拒绝处理请求
if whitelist == nil && global.GVA_CONFIG.Cors.Mode == "strict-whitelist" && !(c.Request.Method == "GET" && c.Request.URL.Path == "/health") {
c.AbortWithStatus(http.StatusForbidden)
} else {
// 非严格白名单模式,无论是否通过检查均放行所有 OPTIONS 方法
if c.Request.Method == http.MethodOptions {
c.AbortWithStatus(http.StatusNoContent)
}
return
}
// OPTIONS 预检:直接结束,避免继续匹配路由导致 404
if c.Request.Method == http.MethodOptions {
c.AbortWithStatus(http.StatusNoContent)
return
}
// 处理请求
c.Next()
}
}