cors.go 434 B

123456789101112131415161718192021
  1. package middleware
  2. import (
  3. "time"
  4. "github.com/gin-contrib/cors"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func CORS() gin.HandlerFunc {
  8. config := cors.Config{
  9. AllowAllOrigins: true,
  10. AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
  11. AllowHeaders: []string{"*"},
  12. ExposeHeaders: []string{"*"},
  13. AllowCredentials: false,
  14. MaxAge: 12 * time.Hour,
  15. }
  16. return cors.New(config)
  17. }