跨域设置
默认设置
srv := nexframe.Server()
srv.WithMiddleware(srv.CORSDefault) //添加默认的跨域
个性化设置
corsOptions := CORSOptions{
AllowDomain: []string{"http://example.com", "http://sub.example.com"},
AllowOrigin: "*", // 允许所有域名
AllowCredentials: "true", // 允许携带凭证(cookies)
ExposeHeaders: "Content-Length, X-Content-Type-Options", // 暴露给客户端的头信息
MaxAge: 86400, // 预检请求的缓存时间(秒)
AllowMethods: "POST, GET, OPTIONS, PUT, DELETE", // 允许的HTTP方法
AllowHeaders: "Origin, X-Requested-With, Content-Type, Accept, Authorization", // 允许的头信息
}
注意事项
最后更新于