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
----------------------------------【喜歡打賞】-------------------------------------------
小主,辛苦啦!文章棒棒噠,賞杯咖啡吧...