Files
bamort/backend/router/setup.go
T

31 lines
930 B
Go
Raw Normal View History

2025-01-03 08:12:38 +01:00
package router
import (
"bamort/config"
2025-01-03 08:12:38 +01:00
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func SetupGin(r *gin.Engine) {
// Build allowed origins list from configuration
allowedOrigins := []string{
config.Cfg.FrontendURL,
"http://localhost:5173", // Development frontend
2026-01-02 10:21:30 +01:00
"http://192.168.0.48:5173", // Development frontend
"http://192.168.0.36:5173", // Development frontend
"https://bamort.trokan.de", // Production frontend
}
2025-01-03 08:12:38 +01:00
// Add CORS middleware
r.Use(cors.New(cors.Config{
//AllowOrigins: []string{"http://localhost:3000"}, // Replace with your frontend's URL
AllowOrigins: allowedOrigins,
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
2025-01-03 08:12:38 +01:00
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * 3600, // Cache preflight for 12 hours
2025-01-03 08:12:38 +01:00
}))
}