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