add gin_mode env

This commit is contained in:
Cipher Vance
2025-11-15 15:41:28 -06:00
parent 0918affe9a
commit ae3a484139

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"log" "log"
"os"
"github.com/rideaware/admin-panel/internal/config" "github.com/rideaware/admin-panel/internal/config"
"github.com/rideaware/admin-panel/internal/database" "github.com/rideaware/admin-panel/internal/database"
@@ -17,11 +18,22 @@ import (
// authenticated routes, and starts the HTTP server on the configured port. // authenticated routes, and starts the HTTP server on the configured port.
func main() { func main() {
cfg := config.Load() cfg := config.Load()
// Set Gin mode based on environment (default to release)
if os.Getenv("GIN_MODE") == "" {
gin.SetMode(gin.ReleaseMode)
}
middleware.Init() middleware.Init()
database.Init(cfg) database.Init(cfg)
defer database.Close() defer database.Close()
router := gin.Default() router := gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())
// Trust only localhost proxy in production
router.SetTrustedProxies([]string{"127.0.0.1", "localhost", "::1"})
router.LoadHTMLGlob("web/templates/*.html") router.LoadHTMLGlob("web/templates/*.html")
router.Static("/static", "web/static") router.Static("/static", "web/static")