beego 跨域请求配置

  • 2019-07-03
  • 浏览 (1553)

beego 跨域请求配置:

beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
AllowCredentials: true,
}))
beego.Run()
参数说明
AllowAllOrigins 允许全部来源设置为true则所有域名都可以访问本网站接口,可以将此配置换成为AllowOrigins:[“允许访问的域名”]
AllowMethods :允许的请求类型
AllowHeaders:允许的头部信息
ExposeHeaders:允许暴露的头信息
AllowCredentials:如果设置,允许共享AuthTuffic证书,如Cookie


0  赞