|
@@ -7,6 +7,7 @@ import ( |
|
@@ -7,6 +7,7 @@ import ( |
7
|
"fmt"
|
7
|
"fmt"
|
8
|
"github.com/astaxie/beego/plugins/cors"
|
8
|
"github.com/astaxie/beego/plugins/cors"
|
9
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
|
9
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
|
|
|
10
|
+ "net/http"
|
10
|
protocol "openapi/pkg/domain"
|
11
|
protocol "openapi/pkg/domain"
|
11
|
"strconv"
|
12
|
"strconv"
|
12
|
"strings"
|
13
|
"strings"
|
|
@@ -179,3 +180,18 @@ func (this *BaseController) Finish() { |
|
@@ -179,3 +180,18 @@ func (this *BaseController) Finish() { |
179
|
log.Debug(fmt.Sprintf("<====Send to uid(%d) ucid(%v) client: %d byte\nRequestId:%s RspBodyData: %s", this.Header.Uid, this.Header.UserId, length, this.Header.GetRequestId(), string(strByte)))
|
180
|
log.Debug(fmt.Sprintf("<====Send to uid(%d) ucid(%v) client: %d byte\nRequestId:%s RspBodyData: %s", this.Header.Uid, this.Header.UserId, length, this.Header.GetRequestId(), string(strByte)))
|
180
|
}
|
181
|
}
|
181
|
}
|
182
|
}
|
|
|
183
|
+
|
|
|
184
|
+func AllowCors() func(ctx *context.Context) {
|
|
|
185
|
+ return func(ctx *context.Context) {
|
|
|
186
|
+ ctx.Output.Header("Access-Control-Allow-Methods", "OPTIONS,DELETE,POST,GET,PUT,PATCH")
|
|
|
187
|
+ //ctx.Output.Header("Access-Control-Max-Age", "3600")
|
|
|
188
|
+ ctx.Output.Header("Access-Control-Allow-Headers", "*")
|
|
|
189
|
+ ctx.Output.Header("Access-Control-Allow-Credentials", "true")
|
|
|
190
|
+ ctx.Output.Header("Access-Control-Allow-Origin", "*") //origin
|
|
|
191
|
+ if ctx.Input.Method() == http.MethodOptions {
|
|
|
192
|
+ // options请求,返回200
|
|
|
193
|
+ ctx.Output.SetStatus(http.StatusOK)
|
|
|
194
|
+ _ = ctx.Output.Body([]byte("options support"))
|
|
|
195
|
+ }
|
|
|
196
|
+ }
|
|
|
197
|
+} |