261a6294cb
* added dynamic configuration of Port in Desktop app * added dynamic configuration of API_URL to docker deployments. Now it works with editing only .env file.
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package router
|
|
|
|
import (
|
|
"bamort/config"
|
|
|
|
"github.com/gin-contrib/cors"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetupGin(r *gin.Engine) {
|
|
var corsConfig cors.Config
|
|
|
|
// Desktop: the Wails WebView origin varies by platform/version (wails.localhost,
|
|
// localhost, null …). Since the server is local, allow all origins.
|
|
if config.Cfg.Environment == "desktop" {
|
|
corsConfig = cors.Config{
|
|
AllowOriginFunc: func(_ string) bool { return true },
|
|
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
|
ExposeHeaders: []string{"Content-Length"},
|
|
AllowCredentials: true,
|
|
MaxAge: 12 * 3600,
|
|
}
|
|
} else {
|
|
allowedOrigins := []string{
|
|
config.Cfg.FrontendURL,
|
|
"http://localhost:5173", // Development frontend
|
|
"http://192.168.0.48:5173", // Development frontend
|
|
"http://192.168.0.36:5173", // Development frontend
|
|
"https://bamort.trokan.de", // Production frontend
|
|
"http://wails.localhost", // Wails desktop WebView
|
|
}
|
|
corsConfig = cors.Config{
|
|
AllowOrigins: allowedOrigins,
|
|
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
|
ExposeHeaders: []string{"Content-Length"},
|
|
AllowCredentials: true,
|
|
MaxAge: 12 * 3600,
|
|
}
|
|
}
|
|
|
|
r.Use(cors.New(corsConfig))
|
|
}
|