You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
336 B

package common
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func UseCors(engine *gin.Engine) {
// 1. 设置中间件
cfg := cors.DefaultConfig()
cfg.AllowAllOrigins = true
cfg.AllowCredentials = true
cfg.AddAllowHeaders("Authorization")
// 2. 初始化,并使用中间件
engine.Use(cors.New(cfg))
}