diff --git a/common/middleware/header.go b/common/middleware/header.go index b1411e565..bb41ea656 100644 --- a/common/middleware/header.go +++ b/common/middleware/header.go @@ -1,10 +1,10 @@ package middleware import ( + "github.com/gin-gonic/gin" + "github.com/go-admin-team/go-admin-core/sdk/config" "net/http" "time" - - "github.com/gin-gonic/gin" ) // NoCache is a middleware function that appends headers @@ -23,7 +23,8 @@ func Options(c *gin.Context) { if c.Request.Method != "OPTIONS" { c.Next() } else { - c.Header("Access-Control-Allow-Origin", "*") + origin := config.ApplicationConfig.AllowOrigin + c.Header("Access-Control-Allow-Origin", origin) c.Header("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS") c.Header("Access-Control-Allow-Headers", "authorization, origin, content-type, accept") c.Header("Allow", "HEAD,GET,POST,PUT,PATCH,DELETE,OPTIONS") diff --git a/config/settings.yml b/config/settings.yml index ca7186159..8b0d647dc 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -12,6 +12,8 @@ settings: writertimeout: 2 # 数据权限功能开关 enabledp: false + #允许访问的域(用于设置前端跨域) + alloworigin: 'http://localhost:9527' logger: # 日志存放路径 path: temp/logs