diff --git a/cmd/api/main.go b/cmd/api/main.go index d81e84b..9cfdab1 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -33,17 +33,22 @@ func main() { log.Info(). Bool("debug", cfg.Server.Debug). Int("port", cfg.Server.Port). + Str("db_host", cfg.Database.Host). + Int("db_port", cfg.Database.Port). + Str("db_name", cfg.Database.Database). + Str("db_user", cfg.Database.User). + Str("redis_url", cfg.Redis.URL). Msg("Starting MyCrib API server") - // Connect to database (retry with backoff) + // Connect to database (retry with shorter backoff for container health checks) var db *gorm.DB - for i := 0; i < 5; i++ { + for i := 0; i < 3; i++ { db, err = database.Connect(&cfg.Database, cfg.Server.Debug) if err == nil { break } log.Warn().Err(err).Int("attempt", i+1).Msg("Failed to connect to database, retrying...") - time.Sleep(time.Duration(i+1) * 2 * time.Second) + time.Sleep(time.Duration(i+1) * time.Second) } if err != nil { log.Fatal().Err(err).Msg("Failed to connect to database after retries") diff --git a/internal/config/config.go b/internal/config/config.go index 2e9ed76..52eff7d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -223,17 +223,15 @@ func setDefaults() { func validate(cfg *Config) error { if cfg.Security.SecretKey == "" { - // In development, use a default key - if cfg.Server.Debug { - cfg.Security.SecretKey = "development-secret-key-change-in-production" - } else { - return fmt.Errorf("SECRET_KEY is required in production") + // Use a default key but log a warning in production + cfg.Security.SecretKey = "change-me-in-production-secret-key-12345" + if !cfg.Server.Debug { + fmt.Println("WARNING: SECRET_KEY not set, using default (insecure)") } } - if cfg.Database.Password == "" && !cfg.Server.Debug { - return fmt.Errorf("POSTGRES_PASSWORD is required") - } + // Database password might come from DATABASE_URL, don't require it separately + // The actual connection will fail if credentials are wrong return nil }