From bcf5b2b8431cb880cb341a264df1a6bd7c7c52b1 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 30 Sep 2025 15:47:19 -0400 Subject: [PATCH 01/11] Changes to same .env file --- .env.sample | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.sample b/.env.sample index 9b60f0e..9bc2b5a 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,5 @@ +APP_ENV +BACKEND_PORT SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h ROOT_DIRECTORY=/home/icarus/mydata POSTGRES_MAIN_USER=icarus -- 2.47.3 From f58bcb7db673d8d45646144f2bf6e5c56886cc94 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 1 Oct 2025 17:12:14 -0400 Subject: [PATCH 02/11] Updated sample env files --- .env.docker.sample | 5 +++++ .env.sample | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.env.docker.sample b/.env.docker.sample index 33ebf08..c448c30 100644 --- a/.env.docker.sample +++ b/.env.docker.sample @@ -1,3 +1,8 @@ +APP_ENV=development +BACKEND_PORT=8000 +FRONTEND_URL=http://localhost:4200 +RUST_LOG=debug +ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h ROOT_DIRECTORY=/home/icarus/mydata POSTGRES_MAIN_USER=icarus diff --git a/.env.sample b/.env.sample index 9bc2b5a..f53ca9a 100644 --- a/.env.sample +++ b/.env.sample @@ -1,5 +1,8 @@ -APP_ENV -BACKEND_PORT +APP_ENV=development +BACKEND_PORT=8000 +FRONTEND_URL=http://localhost:4200 +RUST_LOG=debug +ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h ROOT_DIRECTORY=/home/icarus/mydata POSTGRES_MAIN_USER=icarus -- 2.47.3 From 9c6d47cf6c56cc7756dc94b725fa0c2d0d84517a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 1 Oct 2025 17:16:53 -0400 Subject: [PATCH 03/11] icarus_envy version bump --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 756d04b..003ac58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -872,8 +872,8 @@ dependencies = [ [[package]] name = "icarus_envy" -version = "0.3.2" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2#d84a8144aedf02e1b459d67c4023a7e0833f89fd" +version = "0.3.5" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.5-main-86c5050c7b-006#86c5050c7bd5164bc6e773fc404195023f7f7aaa" dependencies = [ "const_format", "dotenvy", diff --git a/Cargo.toml b/Cargo.toml index b1891d5..176d3ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" } -icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2" } +icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.5-main-86c5050c7b-006" } [dev-dependencies] common-multipart-rfc7578 = { version = "0.7.0" } -- 2.47.3 From 7320f8f2d702745a0696aaf36513b40c7a3deadc Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 1 Oct 2025 17:28:39 -0400 Subject: [PATCH 04/11] Adding CORS --- src/main.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main.rs b/src/main.rs index 369894f..a6a8474 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,43 @@ pub mod init { use song_caller::endpoint as song_endpoints; use song_caller::response as song_responses; + mod cors { + pub async fn configure_cors() -> tower_http::cors::CorsLayer { + let cors = tower_http::cors::CorsLayer::new() + .allow_methods([ + axum::http::Method::GET, + axum::http::Method::POST, + axum::http::Method::PUT, + axum::http::Method::DELETE, + ]) // Specify allowed methods:cite[2] + .allow_headers([ + axum::http::header::CONTENT_TYPE, + axum::http::header::AUTHORIZATION, + ]) // Specify allowed headers:cite[2] + .allow_credentials(true) // If you need to send cookies or authentication headers:cite[2] + .max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2] + + // Dynamically set the allowed origin based on the environment + match std::env::var(icarus_envy::keys::APP_ENV).as_deref() { + Ok("production") => { + // In production, allow only your specific, trusted origins + let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await; + let allowed_origins: Vec = allowed_origins_env.split(",").map(|s| s.parse::().unwrap()).collect(); + cors.allow_origin(allowed_origins) + } + _ => { + // Development (default): Allow localhost origins + cors.allow_origin(vec![ + "http://localhost:8001".parse().unwrap(), + "http://127.0.0.1:8001".parse().unwrap(), + "http://localhost:4200".parse().unwrap(), + "http://127.0.0.1:4200".parse().unwrap(), + ]) + } + } + } + } + #[derive(utoipa::OpenApi)] #[openapi( paths(song_endpoints::queue_song, song_endpoints::link_user_id, song_endpoints::fetch_queue_song, song_endpoints::download_flac, @@ -226,6 +263,7 @@ pub mod init { crate::callers::endpoints::GETALLSONGS, get(crate::callers::song::endpoint::get_all_songs), ) + .layer(cors::configure_cors().await) } pub async fn app() -> axum::Router { -- 2.47.3 From 5108fd56ae450c25cafcc49dc57f3a4b4f17d7ed Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 9 Oct 2025 20:20:23 -0400 Subject: [PATCH 05/11] Added other urls --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index a6a8474..15da91b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,8 @@ pub mod init { _ => { // Development (default): Allow localhost origins cors.allow_origin(vec![ + "http://localhost:3000".parse().unwrap(), + "http://127.0.0.1:3000".parse().unwrap(), "http://localhost:8001".parse().unwrap(), "http://127.0.0.1:8001".parse().unwrap(), "http://localhost:4200".parse().unwrap(), -- 2.47.3 From 980edf1723f49715503a66e053c747dea6800d9a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 9 Oct 2025 20:20:39 -0400 Subject: [PATCH 06/11] Code formatting --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 15da91b..5ca9900 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,7 +86,10 @@ pub mod init { Ok("production") => { // In production, allow only your specific, trusted origins let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await; - let allowed_origins: Vec = allowed_origins_env.split(",").map(|s| s.parse::().unwrap()).collect(); + let allowed_origins: Vec = allowed_origins_env + .split(",") + .map(|s| s.parse::().unwrap()) + .collect(); cors.allow_origin(allowed_origins) } _ => { -- 2.47.3 From 71991c376cde2c76630aa3eca0a7e6d7ccbf9e86 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 9 Oct 2025 20:37:34 -0400 Subject: [PATCH 07/11] Changed allowed urls --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 5ca9900..0146e3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,6 +97,8 @@ pub mod init { cors.allow_origin(vec![ "http://localhost:3000".parse().unwrap(), "http://127.0.0.1:3000".parse().unwrap(), + "http://localhost:8000".parse().unwrap(), + "http://127.0.0.1:8000".parse().unwrap(), "http://localhost:8001".parse().unwrap(), "http://127.0.0.1:8001".parse().unwrap(), "http://localhost:4200".parse().unwrap(), -- 2.47.3 From ba47bd659b646a494b2826118f53ed2c933a853c Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 9 Oct 2025 21:18:01 -0400 Subject: [PATCH 08/11] Modified docker compose. Port changes --- docker-compose.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 7a952eb..7636657 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,7 +10,7 @@ services: ports: # Map host port 8000 to container port 3000 (adjust as needed) # Format: "HOST_PORT:CONTAINER_PORT" - - "8000:3000" + - "8000:8000" env_file: - .env depends_on: @@ -29,7 +29,7 @@ services: container_name: auth_api restart: unless-stopped ports: - - "8001:3000" # Map host port 8000 to container port 8000 (adjust container port based on your app's EXPOSE in Dockerfile) + - "8001:8001" # Map host port 8000 to container port 8000 (adjust container port based on your app's EXPOSE in Dockerfile) # environment: # Environment variables your API needs, e.g., database connection # Add other necessary environment variables -- 2.47.3 From af35fd2017265b53f89af3f5f3abcb8499508aed Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 9 Oct 2025 21:30:28 -0400 Subject: [PATCH 09/11] Changed port --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0146e3c..2b41286 100644 --- a/src/main.rs +++ b/src/main.rs @@ -280,11 +280,14 @@ pub mod init { // TODO: Look into handling this. Seems redundant to run migrations multiple times crate::db::migrations(&pool).await; + let cors = cors::configure_cors().await; + /* let cors = tower_http::cors::CorsLayer::new() .allow_origin("http://localhost:3000".parse::().unwrap()) .allow_methods([Method::GET, Method::POST, Method::PATCH, Method::DELETE]) .allow_credentials(true) .allow_headers([AUTHORIZATION, ACCEPT, CONTENT_TYPE]); + */ routes() .await @@ -310,7 +313,7 @@ fn get_address() -> String { // TODO: Move elsewhere fn get_port() -> String { - String::from("3000") + String::from("8000") } // TODO: Move elsewhere -- 2.47.3 From 6eb91ceaaa56ff6847102a10e058ac0953bc6ce9 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 10 Oct 2025 15:59:08 -0400 Subject: [PATCH 10/11] Cleanup --- src/main.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2b41286..1e39cdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,16 +45,12 @@ async fn main() { } pub mod init { - use axum::routing::{delete, get, patch, post}; use std::time::Duration; + + use axum::routing::{delete, get, patch, post}; use tower_http::timeout::TimeoutLayer; use utoipa::OpenApi; - use axum::http::{ - HeaderValue, Method, - header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE}, - }; - use crate::callers::coverart as coverart_caller; use crate::callers::metadata as metadata_caller; use crate::callers::song as song_caller; @@ -95,12 +91,8 @@ pub mod init { _ => { // Development (default): Allow localhost origins cors.allow_origin(vec![ - "http://localhost:3000".parse().unwrap(), - "http://127.0.0.1:3000".parse().unwrap(), "http://localhost:8000".parse().unwrap(), "http://127.0.0.1:8000".parse().unwrap(), - "http://localhost:8001".parse().unwrap(), - "http://127.0.0.1:8001".parse().unwrap(), "http://localhost:4200".parse().unwrap(), "http://127.0.0.1:4200".parse().unwrap(), ]) @@ -281,13 +273,6 @@ pub mod init { crate::db::migrations(&pool).await; let cors = cors::configure_cors().await; - /* - let cors = tower_http::cors::CorsLayer::new() - .allow_origin("http://localhost:3000".parse::().unwrap()) - .allow_methods([Method::GET, Method::POST, Method::PATCH, Method::DELETE]) - .allow_credentials(true) - .allow_headers([AUTHORIZATION, ACCEPT, CONTENT_TYPE]); - */ routes() .await -- 2.47.3 From fdf312d7c7ce0ed10a4b49e44cc9f43f1e90df37 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 10 Oct 2025 16:09:06 -0400 Subject: [PATCH 11/11] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 003ac58..85333b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -840,7 +840,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.2.0" +version = "0.2.1" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index 176d3ed..5a52206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.2.0" +version = "0.2.1" edition = "2024" rust-version = "1.88" -- 2.47.3