作者 yangfu

cros修改

@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 "errors" 5 "errors"
6 "fmt" 6 "fmt"
7 "github.com/astaxie/beego/context" 7 "github.com/astaxie/beego/context"
8 - "github.com/astaxie/beego/plugins/cors"  
9 "github.com/tiptok/gocomm/common" 8 "github.com/tiptok/gocomm/common"
10 "github.com/tiptok/gocomm/pkg/log" 9 "github.com/tiptok/gocomm/pkg/log"
11 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex" 10 "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex"
@@ -125,19 +124,15 @@ func CreateResponseLogFilter() func(ctx *context.Context) { @@ -125,19 +124,15 @@ func CreateResponseLogFilter() func(ctx *context.Context) {
125 124
126 func AllowCors() func(ctx *context.Context) { 125 func AllowCors() func(ctx *context.Context) {
127 return func(ctx *context.Context) { 126 return func(ctx *context.Context) {
128 - if ctx.Request.Method != "OPTIONS" {  
129 - return 127 + ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
  128 + //ctx.Output.Header("Access-Control-Max-Age", "3600")
  129 + ctx.Output.Header("Access-Control-Allow-Headers", "*")
  130 + ctx.Output.Header("Access-Control-Allow-Credentials", "true")
  131 + ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
  132 + if ctx.Input.Method() == http.MethodOptions {
  133 + // options请求,返回200
  134 + ctx.Output.SetStatus(http.StatusOK)
  135 + _ = ctx.Output.Body([]byte("options support"))
130 } 136 }
131 - f := cors.Allow(&cors.Options{  
132 - AllowOrigins: []string{"*"},  
133 - AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},  
134 - AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Content-Type", "x-requested-with"},  
135 - ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},  
136 - AllowCredentials: true,  
137 - })  
138 - f(ctx)  
139 - ctx.Output.Body([]byte("{}"))  
140 - ctx.Output.SetStatus(http.StatusNoContent)  
141 - return  
142 } 137 }
143 } 138 }