12345678910111213141516171819202122232425262728293031 |
- package cors
-
- import (
- "net/http"
- "strings"
-
- "github.com/gin-contrib/cors"
- "github.com/gin-gonic/gin"
- )
-
- func Cors() gin.HandlerFunc {
- config := cors.DefaultConfig()
-
- config.AddAllowMethods(http.MethodDelete, http.MethodOptions, http.MethodPatch)
- config.AddAllowHeaders("Authorization", "X-Require-Cookie")
- config.AllowCredentials = true
- config.AllowOriginFunc = func(origin string) bool {
- if gin.Mode() == gin.DebugMode {
- return true
- }
-
- if strings.Contains(origin, "links123.com") {
- return true
- }
-
- return false
- }
-
- return cors.New(config)
- }
|