切换导航条
此项目
正在载入...
登录
allied-creation
/
allied-creation-gateway
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
yangfu
3 years ago
提交
af1eab83ae14f22810fd5ca400850beb4d9075aa
1 个父辈
09b63c75
跨域设置
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
18 行增加
和
1 行删除
pkg/port/beego/beego.go
pkg/port/beego/beego.go
查看文件 @
af1eab8
...
...
@@ -2,6 +2,7 @@ package beego
import
(
"encoding/json"
"net/http"
"os"
"strconv"
...
...
@@ -45,7 +46,7 @@ func init() {
}
filters
.
SecureKeyMap
[
"token"
]
=
"x-mmm-accesstoken"
web
.
InsertFilter
(
"/*"
,
web
.
BeforeRouter
,
filters
.
AllowCors
())
web
.
InsertFilter
(
"/*"
,
web
.
BeforeRouter
,
AllowCors
())
web
.
InsertFilter
(
"/*"
,
web
.
BeforeRouter
,
filters
.
CreateRequstLogFilter
(
log
.
Logger
))
web
.
InsertFilter
(
"/v1/web/*"
,
web
.
BeforeExec
,
middleware
.
CheckAccessToken2
())
web
.
InsertFilter
(
"/v1/app/*"
,
web
.
BeforeExec
,
middleware
.
CheckAccessToken2
())
...
...
@@ -60,3 +61,19 @@ func init() {
))
//web.InsertFilterChain("/v1/*", middleware.CheckAccessToken)
}
func
AllowCors
()
func
(
ctx
*
context
.
Context
)
{
return
func
(
ctx
*
context
.
Context
)
{
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", "*,x-mmm-version")
ctx
.
Output
.
Header
(
"Access-Control-Allow-Headers"
,
"Content-Type,X-Mmm-Accesstoken,X-Mmm-Devicetype,X-Mmm-Sign,X-Mmm-Timestamp,X-Mmm-Uuid,X-Mmm-Version"
)
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"
))
}
}
}
...
...
请
注册
或
登录
后发表评论