From 2c03264772e3ac37bc2a5fcaa899c8d71e474a8c Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 26 Sep 2025 15:59:39 -0400 Subject: [PATCH 01/11] Added environment variables for cors support --- .env.docker.sample | 5 +++++ .env.sample | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.env.docker.sample b/.env.docker.sample index ffde663..5d67918 100644 --- a/.env.docker.sample +++ b/.env.docker.sample @@ -1,3 +1,8 @@ +APP_ENV=development +BACKEND_PORT=8001 +FRONTEND_URL=http://localhost:4200 +RUST_LOG=debug +ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH POSTGRES_AUTH_USER=icarus_op diff --git a/.env.sample b/.env.sample index c00c477..1a544f7 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,8 @@ +APP_ENV=development +BACKEND_PORT=8001 +FRONTEND_URL=http://localhost:4200 +RUST_LOG=debug +ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH POSTGRES_AUTH_USER=icarus_op_test -- 2.43.0 From 975e63bf84668b80168c1e712de291440502bea3 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 29 Sep 2025 16:51:28 -0400 Subject: [PATCH 02/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 797ad69..49ee474 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -775,8 +775,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 fb785d1..55f191c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ josekit = { version = "0.10.3" } utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } 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] http-body-util = { version = "0.1.3" } -- 2.43.0 From 8cf991b31d35d162eb9e72e02d90eb6f9814afc4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 29 Sep 2025 16:53:09 -0400 Subject: [PATCH 03/11] Added TODO --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index fdc78b0..75c5de2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +// TODO: Get rid of this file and place the code in more appropriate places pub mod callers; pub mod config; pub mod hashing; -- 2.43.0 From 6ad5b52cf3f0a11725254541be38b77599a20706 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 29 Sep 2025 17:13:44 -0400 Subject: [PATCH 04/11] Added tower-http and added full features to tower --- Cargo.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 49ee474..ae4c579 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -627,6 +627,16 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "byteorder", + "num-traits", +] + [[package]] name = "heck" version = "0.5.0" @@ -766,6 +776,7 @@ dependencies = [ "time", "tokio", "tower", + "tower-http", "tracing-subscriber", "url", "utoipa", @@ -2152,6 +2163,19 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "tower" version = "0.5.2" @@ -2160,14 +2184,32 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", + "hdrhistogram", + "indexmap", "pin-project-lite", + "slab", "sync_wrapper", "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", ] +[[package]] +name = "tower-http" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" +dependencies = [ + "bitflags", + "bytes", + "http", + "pin-project-lite", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-layer" version = "0.3.3" diff --git a/Cargo.toml b/Cargo.toml index 55f191c..dfe990e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ serde = { version = "1.0.219", features = ["derive"] } serde_json = { version = "1.0.140" } tokio = { version = "1.45.1", features = ["rt-multi-thread"] } tracing-subscriber = { version = "0.3.19" } -tower = { version = "0.5.2" } +tower = { version = "0.5.2", features = ["full"] } +tower-http = { version = "0.6.6", features = ["cors"] } hyper = { version = "1.6.0" } sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] } uuid = { version = "1.17.0", features = ["v4", "serde"] } -- 2.43.0 From 80cbaeb4195f825d4fd2afc95f71cc602bb508e4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 29 Sep 2025 17:28:39 -0400 Subject: [PATCH 05/11] Added CORS support --- src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main.rs b/src/main.rs index c13b7f6..edaf8ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,44 @@ mod init { )] struct ApiDoc; + mod cors { + // use tower_http::cors::AllowOrigin; + // use tower_http::cors::CorsLayer; + // use axum::routing::get; + // use axum::routing::Router; + + pub fn configure_cors() -> tower_http::cors::CorsLayer { + // Start building the CORS layer with common settings + 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("ENVIRONMENT").as_deref() { + Ok("production") => { + // In production, allow only your specific, trusted origins + cors.allow_origin(vec![ + "https://www.your-production-domain.com".parse::().unwrap(), + "https://your-production-domain.com".parse().unwrap(), + ]) + } + Ok("staging") => { + // Staging environment + cors.allow_origin("https://staging.your-domain.com".parse::().unwrap()) + } + _ => { + // Development (default): Allow localhost origins + cors.allow_origin(vec![ + "http://localhost:3000".parse().unwrap(), + "http://127.0.0.1:3000".parse().unwrap(), + ]) + } + } + } + } + pub async fn routes() -> Router { // build our application with a route Router::new() @@ -72,6 +110,7 @@ mod init { callers::endpoints::REFRESH_TOKEN, post(callers::login::endpoint::refresh_token), ) + .layer(cors::configure_cors()) } pub async fn app() -> Router { -- 2.43.0 From 92f24d4c1161ba5fa0ca25eb9556ff1f3f57242f Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 29 Sep 2025 17:48:49 -0400 Subject: [PATCH 06/11] CORS support --- src/main.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index edaf8ad..24f2c22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,32 +51,47 @@ mod init { // use axum::routing::get; // use axum::routing::Router; - pub fn configure_cors() -> tower_http::cors::CorsLayer { + pub async fn configure_cors() -> tower_http::cors::CorsLayer { // Start building the CORS layer with common settings 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_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("ENVIRONMENT").as_deref() { + 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.to_string()).collect(); + let allowed_origins: Vec = allowed_origins_env.split(",").map(|s| s.parse::().unwrap()).collect(); + cors.allow_origin(allowed_origins) + // cors.allow_origin(vec![""]) + /* cors.allow_origin(vec![ - "https://www.your-production-domain.com".parse::().unwrap(), + "https://www.your-production-domain.com" + .parse::() + .unwrap(), "https://your-production-domain.com".parse().unwrap(), ]) - } - Ok("staging") => { - // Staging environment - cors.allow_origin("https://staging.your-domain.com".parse::().unwrap()) + */ } _ => { // 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:4200".parse().unwrap(), + "http://127.0.0.1:4200".parse().unwrap(), ]) } } @@ -110,7 +125,7 @@ mod init { callers::endpoints::REFRESH_TOKEN, post(callers::login::endpoint::refresh_token), ) - .layer(cors::configure_cors()) + .layer(cors::configure_cors().await) } pub async fn app() -> Router { -- 2.43.0 From b446b12a9fd1c673e6321df7d4997b7f5676b730 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 9 Oct 2025 21:32:07 -0400 Subject: [PATCH 07/11] Changed port --- src/config/mod.rs | 2 +- src/main.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index f34b535..7ca5adb 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -6,5 +6,5 @@ fn get_address() -> String { } fn get_port() -> String { - String::from("3000") + String::from("8001") } diff --git a/src/main.rs b/src/main.rs index 24f2c22..9cb5d38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,10 @@ mod init { // 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.to_string()).collect(); - 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) // cors.allow_origin(vec![""]) /* -- 2.43.0 From d1d3936c7833995b68e014a9d3cb3563d3955a90 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 9 Oct 2025 21:32:41 -0400 Subject: [PATCH 08/11] Docker compose port change --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index c6c0140..80d8100 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,7 @@ services: container_name: icarus_auth # Optional: Give the container a specific name ports: # Map host port 8000 to container port 3000 (adjust as needed) - - "8000:3000" + - "8001:8001" env_file: - .env depends_on: -- 2.43.0 From f87de77aa67a72e7b3c3eccefde4b0e33b193adc Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 15:38:02 -0400 Subject: [PATCH 09/11] Code cleanup --- src/main.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9cb5d38..4a8ee2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,11 +46,6 @@ mod init { struct ApiDoc; mod cors { - // use tower_http::cors::AllowOrigin; - // use tower_http::cors::CorsLayer; - // use axum::routing::get; - // use axum::routing::Router; - pub async fn configure_cors() -> tower_http::cors::CorsLayer { // Start building the CORS layer with common settings let cors = tower_http::cors::CorsLayer::new() @@ -70,29 +65,16 @@ mod init { // 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.to_string()).collect(); let allowed_origins: Vec = allowed_origins_env .split(",") .map(|s| s.parse::().unwrap()) .collect(); cors.allow_origin(allowed_origins) - // cors.allow_origin(vec![""]) - /* - cors.allow_origin(vec![ - "https://www.your-production-domain.com" - .parse::() - .unwrap(), - "https://your-production-domain.com".parse().unwrap(), - ]) - */ } _ => { // Development (default): Allow localhost origins cors.allow_origin(vec![ - "http://localhost:8000".parse().unwrap(), - "http://127.0.0.1:8000".parse().unwrap(), "http://localhost:4200".parse().unwrap(), "http://127.0.0.1:4200".parse().unwrap(), ]) -- 2.43.0 From b770c5ee78e738f23f7a66f4bbd9a4aefdc34176 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 16:08:43 -0400 Subject: [PATCH 10/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 ae4c579..c793376 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -759,7 +759,7 @@ dependencies = [ [[package]] name = "icarus_auth" -version = "0.5.0" +version = "0.5.1" dependencies = [ "argon2", "axum", diff --git a/Cargo.toml b/Cargo.toml index dfe990e..081b602 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_auth" -version = "0.5.0" +version = "0.5.1" edition = "2024" rust-version = "1.88" -- 2.43.0 From 9c03010bc345c8609c188a8aa9492ac4c12f0215 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 16:25:42 -0400 Subject: [PATCH 11/11] Comment change --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4a8ee2a..0a290b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ async fn main() { let app = init::app().await; - // run our app with hyper, listening globally on port 3000 + // run our app with hyper, listening globally on port 8001 let url = config::get_full(); let listener = tokio::net::TcpListener::bind(url).await.unwrap(); axum::serve(listener, app).await.unwrap(); -- 2.43.0