cors.go 647 B

1234567891011121314151617181920
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/contrib/cors"
  4. "github.com/gin-gonic/gin"
  5. "time"
  6. )
  7. func CORS() gin.HandlerFunc {
  8. config := cors.DefaultConfig()
  9. config.AllowedHeaders = []string{"Authorization", "Content-Type", "Origin",
  10. "Connection", "Accept-Encoding", "Accept-Language", "Host"}
  11. config.AllowedMethods = []string{"GET", "POST", "DELETE", "OPTIONS", "PUT"}
  12. config.AllowCredentials = true
  13. config.MaxAge = 12 * time.Hour
  14. // if you want to allow all origins, comment the following two lines
  15. config.AllowAllOrigins = false
  16. config.AllowedOrigins = []string{"https://message-pusher.vercel.app"}
  17. return cors.New(config)
  18. }