作者 yangfu

cors

正在显示 1 个修改的文件 包含 4 行增加16 行删除
@@ -5,13 +5,13 @@ import ( @@ -5,13 +5,13 @@ import (
5 "github.com/astaxie/beego" 5 "github.com/astaxie/beego"
6 "github.com/astaxie/beego/context" 6 "github.com/astaxie/beego/context"
7 beeorm "github.com/astaxie/beego/orm" 7 beeorm "github.com/astaxie/beego/orm"
8 - "github.com/astaxie/beego/plugins/cors"  
9 _ "github.com/go-sql-driver/mysql" 8 _ "github.com/go-sql-driver/mysql"
10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
11 "gitlab.fjmaimaimai.com/mmm-go/gocomm/config" 10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
12 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 11 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
13 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" 12 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
14 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" 13 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
  14 + "opp/controllers"
15 "opp/internal/utils" 15 "opp/internal/utils"
16 _ "opp/routers" 16 _ "opp/routers"
17 "opp/services/contrab" 17 "opp/services/contrab"
@@ -86,7 +86,7 @@ func main() { @@ -86,7 +86,7 @@ func main() {
86 log.Info("app on start!") 86 log.Info("app on start!")
87 log.Info("Beego Run Mode:", beego.BConfig.RunMode) 87 log.Info("Beego Run Mode:", beego.BConfig.RunMode)
88 88
89 - AllowCors() 89 + StaticFileAllowCors()
90 90
91 beego.InsertFilter("file/opp/*", beego.BeforeStatic, FilterBeforeStatic) 91 beego.InsertFilter("file/opp/*", beego.BeforeStatic, FilterBeforeStatic)
92 92
@@ -109,20 +109,8 @@ var FilterBeforeStatic = func(ctx *context.Context) { @@ -109,20 +109,8 @@ var FilterBeforeStatic = func(ctx *context.Context) {
109 } 109 }
110 } 110 }
111 111
112 -func AllowCors() {  
113 - beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{  
114 - //允许访问所有源  
115 - AllowAllOrigins: true,  
116 - //可选参数"GET", "POST", "PUT", "DELETE", "OPTIONS" (*为所有)  
117 - //其中Options跨域复杂请求预检  
118 - AllowMethods: []string{"*"},  
119 - //指的是允许的Header的种类  
120 - AllowHeaders: []string{"*"},  
121 - //公开的HTTP标头列表  
122 - ExposeHeaders: []string{"Content-Length"},  
123 - //如果设置,则允许共享身份验证凭据,例如cookie  
124 - AllowCredentials: true,  
125 - })) 112 +func StaticFileAllowCors() {
  113 + beego.InsertFilter("/file/opp/*", beego.BeforeRouter, controllers.AllowOption)
126 } 114 }
127 115
128 func NewBeeormEngine(conf config.Mysql) { 116 func NewBeeormEngine(conf config.Mysql) {