s := g.Server()
s.BindHookHandlerByMap("/*any", map[string]ghttp.HandlerFunc{
"BeforeServe": func(r *ghttp.Request) {
r.Response.CORS(ghttp.CORSOptions{
AllowOrigin: "*",
AllowMethods: "POST, GET, OPTIONS, PUT, DELETE,UPDATE,",
AllowCredentials: "false",
MaxAge: 1728000,
AllowHeaders: "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma",
ExposeHeaders: "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar",
})
if r.Request.Method == "OPTIONS" {
_ = r.Response.WriteJson(g.Map{
"code": http.StatusOK,
"msg": "",
"data": nil,
})
r.ExitAll()
}
}})
goframe 框架跨域 设置
原创
©著作权归作者所有:来自51CTO博客作者go工程师的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
GoFrame系列:1、GoFrame简介
GoFrame系列:1、GoFrame简介文章目录GoFrame系列
Go GoFrame github php nginx -
goframe框架学习之打印日志
【代码】goframe框架学习之打印日志。
学习 开发语言 golang github -
git upstream
一个分支的upstream,其实就是与远程分支做关联,告诉git,默认此分支为推送及拉取的远程分
git upstream 远程仓库 github -
goframe框架学习之数据返回
【代码】goframe框架学习之数据返回。
学习 开发语言 golang github Server -
upstream
nginx upstream name的不能有特殊字符,各种结合等
nginx 特殊字符