From 42091492d591511d9e77ded5cb01ff60e89cb06b Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Thu, 28 Aug 2025 16:26:48 -0400 Subject: [PATCH] Make backend API URL configurable via environment variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated frontend to use BACKEND_API_URL environment variable at compile time with fallback to localhost. Added configuration to Trunk.toml and .env.example for development. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .env.example | 4 ++++ Trunk.toml | 3 +++ src/auth.rs | 10 ++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 3f7142b..ec187ae 100644 --- a/.env.example +++ b/.env.example @@ -9,5 +9,9 @@ CALDAV_CALENDAR_PATH=/calendars/your-username/personal/ # Optional: Task/Todo collection path CALDAV_TASKS_PATH=/calendars/your-username/tasks/ +# Backend API Configuration +# Set this to point to your backend API server +BACKEND_API_URL=http://localhost:3000/api + # Development settings RUST_LOG=info \ No newline at end of file diff --git a/Trunk.toml b/Trunk.toml index fe27fce..ca0054e 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -2,6 +2,9 @@ target = "index.html" dist = "dist" +[env] +BACKEND_API_URL = "http://localhost:3000/api" + [watch] watch = ["src", "Cargo.toml"] ignore = ["backend/"] diff --git a/src/auth.rs b/src/auth.rs index 45a9207..bc39aa7 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -50,10 +50,12 @@ pub struct AuthService { impl AuthService { pub fn new() -> Self { - // Default to localhost backend - could be configurable via env var in the future - Self { - base_url: "http://localhost:3000/api".to_string(), - } + // Get backend URL from environment variable at compile time, fallback to localhost + let base_url = option_env!("BACKEND_API_URL") + .unwrap_or("http://localhost:3000/api") + .to_string(); + + Self { base_url } } pub async fn register(&self, request: RegisterRequest) -> Result {