...
|
...
|
@@ -18,8 +18,28 @@ type BaseController struct { |
|
|
beego.Controller
|
|
|
}
|
|
|
|
|
|
func (this *BaseController) Options() {
|
|
|
this.AllowCross() //允许跨域
|
|
|
this.Data["json"] = map[string]interface{}{"status": 204, "message": "ok", "moreinfo": ""}
|
|
|
this.ServeJSON()
|
|
|
}
|
|
|
|
|
|
func (this *BaseController) AllowCross() {
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
|
|
|
//this.Ctx.WriteString("")
|
|
|
}
|
|
|
|
|
|
//Prepare 实现beego.ControllerInterface 的接口
|
|
|
func (this *BaseController) Prepare() {
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
|
|
|
if this.Ctx.Input.Method() == "OPTIONS" {
|
|
|
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
|
//this.Ctx.WriteString("")
|
|
|
return
|
|
|
}
|
|
|
p := this.Ctx.Input.GetData("RouterPattern")
|
|
|
fmt.Println("====>r:", p)
|
|
|
}
|
...
|
...
|
|