cors.go 570 B

1234567891011121314151617
  1. package middleware
  2. import (
  3. "github.com/gin-contrib/cors"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // Cors 跨域配置
  7. func Cors() gin.HandlerFunc {
  8. config := cors.DefaultConfig()
  9. config.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}
  10. config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Cookie", "Token", "Authorization"}
  11. config.ExposeHeaders = []string{"Origin", "Content-Length", "Content-Type", "Cookie", "Token"}
  12. config.AllowOrigins = []string{"*"}
  13. config.AllowCredentials = true
  14. return cors.New(config)
  15. }