diff --git a/backend/config/tui-postgres.env b/backend/config/tui-postgres.env index e609363..9fd8d98 100644 --- a/backend/config/tui-postgres.env +++ b/backend/config/tui-postgres.env @@ -1,3 +1,3 @@ # Postgres TUI Configuration RUST_LOG=info -DATABASE_URL=postgres://postgres:password@localhost:5432/pylon \ No newline at end of file +DATABASE_URL=postgres://postgres:password@localhost:5432/pylon \ No newline at end of file diff --git a/backend/crates/sharenet-api-memory/src/main.rs b/backend/crates/sharenet-api-memory/src/main.rs index d59d7cd..42f6998 100644 --- a/backend/crates/sharenet-api-memory/src/main.rs +++ b/backend/crates/sharenet-api-memory/src/main.rs @@ -5,13 +5,12 @@ use api::run as run_api; use application::Service; use domain::{User, Product}; use memory::{InMemoryProductRepository, InMemoryUserRepository}; -use dotenvy::dotenv; use std::env; #[tokio::main] async fn main() -> anyhow::Result<()> { - // Load environment variables from .env file - dotenv().ok(); + // Load environment variables from config file + dotenvy::from_path("config/api-memory.env").ok(); // Get configuration from environment variables let server_addr = env::var("SERVER_ADDR").unwrap_or_else(|_| "127.0.0.1:3000".to_string()); diff --git a/backend/crates/sharenet-api-postgres/src/main.rs b/backend/crates/sharenet-api-postgres/src/main.rs index 3f5b549..ed75ad4 100644 --- a/backend/crates/sharenet-api-postgres/src/main.rs +++ b/backend/crates/sharenet-api-postgres/src/main.rs @@ -6,13 +6,13 @@ use application::Service; use domain::{User, Product}; use postgres::{PostgresProductRepository, PostgresUserRepository}; use sqlx::postgres::PgPoolOptions; -use dotenvy::dotenv; +use dotenvy; use std::env; #[tokio::main] async fn main() -> anyhow::Result<()> { - // Load environment variables from .env file - dotenv().ok(); + // Load environment variables from config file + dotenvy::from_path("config/api-postgres.env").ok(); // Get configuration from environment variables let server_addr = env::var("SERVER_ADDR").unwrap_or_else(|_| "127.0.0.1:3000".to_string()); diff --git a/backend/crates/sharenet-tui-postgres/src/main.rs b/backend/crates/sharenet-tui-postgres/src/main.rs index 023523c..4744820 100644 --- a/backend/crates/sharenet-tui-postgres/src/main.rs +++ b/backend/crates/sharenet-tui-postgres/src/main.rs @@ -4,7 +4,38 @@ use tui::run_tui; #[tokio::main] async fn main() -> Result<()> { - dotenvy::dotenv().ok(); + // Debug: Print current working directory + println!("Current working directory: {:?}", std::env::current_dir()?); + + // Try multiple possible paths for the environment file + let env_paths = [ + "config/tui-postgres.env", + "../config/tui-postgres.env", + "../../config/tui-postgres.env", + ]; + + let mut env_loaded = false; + for path in &env_paths { + println!("Trying to load environment from: {}", path); + if dotenvy::from_path(path).is_ok() { + println!("Successfully loaded environment from: {}", path); + env_loaded = true; + break; + } else { + println!("Failed to load environment from: {}", path); + } + } + + if !env_loaded { + eprintln!("Warning: Could not load environment file from any of the expected paths"); + } + + // Debug: Print DATABASE_URL if it exists + match std::env::var("DATABASE_URL") { + Ok(url) => println!("DATABASE_URL found: {}", url), + Err(e) => println!("DATABASE_URL not found: {}", e), + } + let pool = sqlx::PgPool::connect(&std::env::var("DATABASE_URL")?).await?; let user_service = PostgresUserService::new(postgres::PostgresUserRepository::new(pool.clone())); let product_service = PostgresProductService::new(postgres::PostgresProductRepository::new(pool));