You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
807 B
27 lines
807 B
4 years ago
|
package manage
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func CORS() gin.HandlerFunc {
|
||
|
return func(c *gin.Context) {
|
||
|
origin := c.Request.Header.Get("Origin")
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
|
||
|
c.Writer.Header().Set("Access-Control-Max-Age", fmt.Sprintf("%d", 6000))
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||
|
c.Writer.Header().Set(
|
||
|
"Access-Control-Allow-Headers",
|
||
|
"Content-Type, Cookie, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Recook-ID, X-Recook-Token, X-Requested-With, X-Recook-GYSToken,X-Recook-GysID")
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET")
|
||
|
|
||
|
if c.Request.Method == "OPTIONS" {
|
||
|
c.AbortWithStatus(200)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.Next()
|
||
|
}
|
||
|
}
|