Please answer these questions before submitting your issue. Thanks!
bee version)?| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
____/ ___| ___| v1.6.0
├── Beego : 1.7.1
├── GoVersion : go1.6.4
├── GOOS : windows
├── GOARCH : amd64
├── NumCPU : 4
├── GOPATH : C:\Projects\Go
├── GOROOT : C:\Go\
├── Compiler : gc
└── Date : Monday, 6 Feb 2017
2.What version of windows you use for running this code(go env)
set GOARCH=amd64
set GOBIN=C:\Projects\Go\bin
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Projects\Go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
package main
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/plugins/cors"
_ "leavepost/routers"
)
func main() {
if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"https://*.foo.com"},
AllowMethods: []string{"PUT", "PATCH"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
beego.Run()
}
My Folder structure is as follows
Enabling of the cors plugin
cannot use cors.Allow(&cors.Options literal) (type "github.com/astaxie/beego".FilterFunc) as type "leavepost/vendor/github.com/astaxie/beego".FilterFunc in argument to "leavepost/vendor/github.com/astaxie/beego".InsertFilterAppreciate any help.Thanks
Ran into the same issue, would have been nice to update why this was closed?
I agree. I'm having the same issue
i have the same issue
Missed a param, now add the true. Working for me.
// 如下支持跨域
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowAllOrigins: true,
// AllowOrigins: []string{"https://*.foo.com"},
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,
}), true)
beego.Run()
@xiaoping378
Allowing all origins with CORS is the same as leaving your car door unlocked with the keys in ignition, with your laptop in the back seat, its password is written on a stickie note, and there are photos which could be used to extort you, or cause great shame in the near future.
It really should not be done...
ran into this problem as well. What can we do other than set AllowAllOrigins to be true?
ran into this problem as well. set AllowAllOrigins to true didn't work, any ideas about this problem?
ran into this problem as well. set
AllowAllOriginstotruedidn't work, any ideas about this problem?
emm, seems I found the way to solve this problem, must download the file cors.go first before import it
Most helpful comment
Missed a param, now add the
true. Working for me.