This commit is contained in:
ljw
2024-09-13 15:57:29 +08:00
commit c53df223d1
112 changed files with 14353 additions and 0 deletions

23
http/middleware/cors.go Normal file
View File

@@ -0,0 +1,23 @@
package middleware
import (
"github.com/gin-gonic/gin"
"net/http"
)
// Cors 跨域
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
origin := c.GetHeader("Origin")
//fmt.Println("origin", origin)
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Headers", "api-token,content-type,authorization ")
c.Header("Access-Control-Allow-Methods", c.Request.Method)
c.Header("Access-Control-Allow-Credentials", "true")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
c.Next()
}
}