作者 yangfu

cors

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