api-base/router/middleware/cors.go
2020-08-16 17:39:13 +08:00

15 lines
296 B
Go

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)
}