backend-service/internal/middleware/cors.go
ats-tech25 a7cd28f3af chore(dependencies): Update project dependencies and middleware packages
- Upgrade Go module dependencies to latest versions
- Add new middleware packages for CORS, logging, rate limiting, and security
- Update go.mod and go.sum with latest package versions
- Integrate new middleware components into server configuration
- Improve project dependency management and middleware infrastructure
2025-11-06 09:31:51 +00:00

47 lines
1018 B
Go

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
})
}