package middleware import ( "time" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) // CORSMiddleware handles Cross-Origin Resource Sharing for frontend integration func CORSMiddleware() gin.HandlerFunc { return cors.New(cors.Config{ AllowOrigins: []string{ "http://localhost:3000", // Next.js development server "http://localhost:3001", // Alternative frontend port "https://localhost:3000", // HTTPS development "https://localhost:3001", // HTTPS alternative // Add production domains here when deploying }, AllowMethods: []string{ "GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", }, AllowHeaders: []string{ "Origin", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "Accept", "Cache-Control", "X-Requested-With", }, ExposeHeaders: []string{ "Content-Length", "Content-Type", }, AllowCredentials: true, MaxAge: 12 * time.Hour, // Preflight cache duration }) }