1234567891011121314151617181920212223242526272829303132 |
- 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)
- // x-requested-with antd上传组件需要
- config.AddAllowHeaders("Authorization", "X-Require-Cookie", "X-Device", "x-requested-with", "X-Tourist-Id")
- config.AllowCredentials = true
- config.AllowOriginFunc = func(origin string) bool {
- if gin.Mode() == gin.DebugMode {
- return true
- }
-
- if strings.Contains(origin, "bilingo.com") || strings.Contains(origin, "links123.com") {
- return true
- }
-
- return false
- }
-
- return cors.New(config)
- }
|