🎨 修改临时数据库,新增跨域中间件

This commit is contained in:
2025-07-23 02:38:53 +08:00
parent 502a9b82d7
commit 666527b976
4 changed files with 93 additions and 71 deletions

View File

@@ -71,3 +71,19 @@ func checkCors(currentOrigin string) *config.CORSWhitelist {
}
return nil
}
func AllCors() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
c.Writer.Header().Set("Access-Control-Allow-Headers", "*")
c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length, Content-Type")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
}
}