7 Star 2 Fork 2

赵康铭/tinyTicktok

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cors.go 676 Bytes
一键复制 编辑 原始数据 按行查看 历史
weirdo0314 提交于 2022-05-16 18:42 +08:00 . feat:append middleware
package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
)
// Cors 跨域中间件
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers",
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Token, Language, From")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zhaokangming/tiny-ticktok.git
git@gitee.com:zhaokangming/tiny-ticktok.git
zhaokangming
tiny-ticktok
tinyTicktok
dcbaf51081e9

搜索帮助