【发布时间】:2021-06-16 14:50:51
【问题描述】:
我使用 Beego/Golang 作为我的后端,在尝试从我的域中获取 URL 时遇到No 'Access-Control-Allow-Origin' header 的问题。我在谷歌上搜索并将其放入func main(),但它仍然不起作用,我仍然有同样的错误。
// (my own code) FilterUser is used to redirect users to login
// when they try to access some pages without logging in
beego.InsertFilter("/*", beego.BeforeExec, FilterUser)
// This is what I found on Google
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowMethods: []string{"GET, POST, PUT, DELETE, OPTIONS"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
【问题讨论】: