api-base/router/middleware/cors.go

15 lines
296 B
Go
Raw Normal View History

2020-08-16 09:39:13 +00:00
package middleware
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func Cors() gin.HandlerFunc {
corsOpts := cors.DefaultConfig()
corsOpts.AllowCredentials = true
corsOpts.AllowOriginFunc = func(origin string) bool { return origin != "" }
return cors.New(corsOpts)
}