| 31 | } |
| 32 | |
| 33 | func Cors() gin.HandlerFunc { |
| 34 | return func(c *gin.Context) { |
| 35 | method := c.Request.Method |
| 36 | origin := c.Request.Header.Get("Origin") |
| 37 | if origin != "" { |
| 38 | c.Header("Access-Control-Allow-Origin", "*") |
| 39 | c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") |
| 40 | c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization") |
| 41 | c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type") |
| 42 | c.Header("Access-Control-Allow-Credentials", "true") |
| 43 | } |
| 44 | if method == "OPTIONS" { |
| 45 | c.AbortWithStatus(http.StatusNoContent) |
| 46 | } |
| 47 | c.Next() |
| 48 | } |
| 49 | } |