|
@@ -18,8 +18,28 @@ type BaseController struct { |
|
@@ -18,8 +18,28 @@ type BaseController struct { |
18
|
beego.Controller
|
18
|
beego.Controller
|
19
|
}
|
19
|
}
|
20
|
|
20
|
|
|
|
21
|
+func (this *BaseController) Options() {
|
|
|
22
|
+ this.AllowCross() //允许跨域
|
|
|
23
|
+ this.Data["json"] = map[string]interface{}{"status": 204, "message": "ok", "moreinfo": ""}
|
|
|
24
|
+ this.ServeJSON()
|
|
|
25
|
+}
|
|
|
26
|
+
|
|
|
27
|
+func (this *BaseController) AllowCross() {
|
|
|
28
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
29
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
|
30
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
|
|
|
31
|
+ //this.Ctx.WriteString("")
|
|
|
32
|
+}
|
|
|
33
|
+
|
21
|
//Prepare 实现beego.ControllerInterface 的接口
|
34
|
//Prepare 实现beego.ControllerInterface 的接口
|
22
|
func (this *BaseController) Prepare() {
|
35
|
func (this *BaseController) Prepare() {
|
|
|
36
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
37
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
|
|
|
38
|
+ if this.Ctx.Input.Method() == "OPTIONS" {
|
|
|
39
|
+ this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
|
40
|
+ //this.Ctx.WriteString("")
|
|
|
41
|
+ return
|
|
|
42
|
+ }
|
23
|
p := this.Ctx.Input.GetData("RouterPattern")
|
43
|
p := this.Ctx.Input.GetData("RouterPattern")
|
24
|
fmt.Println("====>r:", p)
|
44
|
fmt.Println("====>r:", p)
|
25
|
}
|
45
|
}
|