goframe框架跨域设置-创新互联
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()
}
}})
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
创新互联建站是一家专业提供蚌山企业网站建设,专注与成都网站建设、做网站、H5技术、小程序制作等业务。10年已为蚌山众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。当前题目:goframe框架跨域设置-创新互联
标题来源:http://pwwzsj.com/article/doihpd.html