Go-gin CORS 跨域中间件
Posted bob-wei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Go-gin CORS 跨域中间件相关的知识,希望对你有一定的参考价值。
原文:https://stackoverflow.com/questions/29418478/go-gin-framework-cors
func CORSMiddleware() 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") c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT") if c.Request.Method == "OPTIONS" { c.AbortWithStatus(204) return } c.Next() } }
以上是关于Go-gin CORS 跨域中间件的主要内容,如果未能解决你的问题,请参考以下文章