-
Notifications
You must be signed in to change notification settings - Fork 0
/
cors.go
34 lines (30 loc) · 872 Bytes
/
cors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package middleware
import (
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func Cors() gin.HandlerFunc {
return cors.New(getCorsConfig())
}
func getCorsConfig() cors.Config {
return cors.Config{
// AllowOrigins: []string{"https://www.baidu.com"},
AllowOriginFunc: func(origin string) bool {
// return origin == "https://www.baidu.com"
return true
},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{
"Origin", "Content-Type", "Accept", "User-Agent", "Cookie", "Authorization",
"X-Auth-Token", "X-Requested-With", "x-wechat-type", "x-platform",
},
AllowCredentials: true,
ExposeHeaders: []string{
"Authorization", "Content-MD5",
// 分页响应头
"Link", "X-More-Resource", "X-Pagination-Info", "X-Total-Count", "X-Has-More",
},
MaxAge: 12 * time.Hour,
}
}