beego开启CORS
问题 要在Beego中开启CORS,需要使用插件cors,并针对不同的路由类型进行设置。 示例 普通路由 beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{ AllowOrigins: string{"*"}, //AllowMethods: string{"POST", "GET", "OPTIONS"}, //AllowHeaders: string{"Origin"}, //ExposeHeaders: string{"Content-Length"}, //AllowCredentials: true, })) 静态文件路由 beego.InsertFilter("*", beego.BeforeStatic, cors.Allow(&cors.Options{ AllowOrigins: string{"*"}, //AllowMethods: string{"POST", "GET", "OPTIONS"}, //AllowHeaders: string{"Origin"}, //ExposeHeaders: string{"Content-Length"}, //AllowCredentials: true, }))