1 Star 0 Fork 0

xingang / gcore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Cors.go 649 Bytes
一键复制 编辑 原始数据 按行查看 历史
xingang 提交于 2022-04-15 14:23 . 公共中间件
package middlewares
import (
"github.com/gin-gonic/gin"
"net/http"
)
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
var origin = c.Request.Header.Get("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", origin)
}
c.Header("Access-Control-Allow-Credentials", "true")
c.Header("Access-Control-Allow-Headers", "token,x-token,Content-Type,Cookies,UserSessionCacheConst")
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
if method == "OPTIONS" {
//c.AbortWithStatus(http.StatusNoContent)
c.AbortWithStatus(http.StatusOK)
}
c.Next()
}
}
1
https://gitee.com/qq358678184_admin/gcore.git
git@gitee.com:qq358678184_admin/gcore.git
qq358678184_admin
gcore
gcore
996657994fe3

搜索帮助