beego解决跨域问题

beego解决跨域问题

import( "github.com/astaxie/beego/plugins/cors")

func main() {
    //InsertFilter是提供一个过滤函数
	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,
	}))
	beego.Run()

}

参考链接

https://www.cnblogs.com/dannyyao/p/8047319.html

----------------------------------【喜欢打赏】-------------------------------------------

小主,辛苦啦!文章棒棒哒,赏杯咖啡吧...
打赏

----------------------------------【喜欢打赏】-------------------------------------------

原文地址:https://www.cnblogs.com/tomtellyou/p/12257637.html