|
@@ -5,10 +5,12 @@ import ( |
|
@@ -5,10 +5,12 @@ 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"
|
8
|
"github.com/tiptok/gocomm/common"
|
9
|
"github.com/tiptok/gocomm/common"
|
9
|
"github.com/tiptok/gocomm/pkg/log"
|
10
|
"github.com/tiptok/gocomm/pkg/log"
|
10
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex"
|
11
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex"
|
11
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
|
12
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
|
|
|
13
|
+ "net/http"
|
12
|
"strconv"
|
14
|
"strconv"
|
13
|
"strings"
|
15
|
"strings"
|
14
|
"time"
|
16
|
"time"
|
|
@@ -120,3 +122,22 @@ func CreateResponseLogFilter() func(ctx *context.Context) { |
|
@@ -120,3 +122,22 @@ func CreateResponseLogFilter() func(ctx *context.Context) { |
120
|
log.Debug(fmt.Sprintf("<====Send User:%v RequestId:%v BodyData:%s", ctx.Input.GetData("x-mmm-id"), requestId, body))
|
122
|
log.Debug(fmt.Sprintf("<====Send User:%v RequestId:%v BodyData:%s", ctx.Input.GetData("x-mmm-id"), requestId, body))
|
121
|
}
|
123
|
}
|
122
|
}
|
124
|
}
|
|
|
125
|
+
|
|
|
126
|
+func AllowCors() func(ctx *context.Context) {
|
|
|
127
|
+ return func(ctx *context.Context) {
|
|
|
128
|
+ if ctx.Request.Method != "OPTIONS" {
|
|
|
129
|
+ return
|
|
|
130
|
+ }
|
|
|
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
|
+ }
|
|
|
143
|
+} |