add: CORS

This commit is contained in:
$(pass /github/name)
2024-08-22 11:27:27 +02:00
parent ee66835649
commit 682c50574b
5 changed files with 151 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
package middlewares
import (
"GoMembership/internal/config"
"GoMembership/pkg/logger"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func CORSMiddleware() gin.HandlerFunc {
logger.Info.Print("Applying CORS")
return cors.New(cors.Config{
AllowOrigins: []string{config.BaseURL}, // Add your frontend URL(s)
AllowMethods: []string{"GET", "POST"}, // "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization", "X-Requested-With"},
// ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * 60 * 60, // 12 hours
})
}