12345678910111213141516171819202122 |
- package middleware
- import (
- "github.com/gin-gonic/gin"
- "net/http"
- )
- func CORSMiddleware() gin.HandlerFunc {
- return func(c *gin.Context) {
- method := c.Request.Method
- c.Header("Access-Control-Allow-Origin", "*")
- c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
- c.Header("Access-Control-Allow-Headers", "sec-fetch-dest,sec-fetch-mode,sec-fetch-site,Access-Control-Allow-Origin,X-Mode,Authorization, Content-Length, X-CSRF-Token, Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma,timestamp,nonce,sign,x-vs-language,Debug,App-Version,language,X-Forwarded-For,X-Real-IP")
- c.Header("Access-Control-Allow-Credentials", "true")
- if method == "OPTIONS" {
- c.AbortWithStatus(http.StatusNoContent)
- return
- }
- c.Next()
- }
- }
|