Code cleanup
Some checks failed
Rust Build / Check (pull_request) Successful in 34s
Rust Build / Test Suite (pull_request) Failing after 1m5s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 38s
Rust Build / build (pull_request) Successful in 56s
Some checks failed
Rust Build / Check (pull_request) Successful in 34s
Rust Build / Test Suite (pull_request) Failing after 1m5s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 38s
Rust Build / build (pull_request) Successful in 56s
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -46,11 +46,6 @@ mod init {
|
|||||||
struct ApiDoc;
|
struct ApiDoc;
|
||||||
|
|
||||||
mod cors {
|
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 {
|
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
|
||||||
// Start building the CORS layer with common settings
|
// Start building the CORS layer with common settings
|
||||||
let cors = tower_http::cors::CorsLayer::new()
|
let cors = tower_http::cors::CorsLayer::new()
|
||||||
@@ -70,29 +65,16 @@ mod init {
|
|||||||
// Dynamically set the allowed origin based on the environment
|
// Dynamically set the allowed origin based on the environment
|
||||||
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
||||||
Ok("production") => {
|
Ok("production") => {
|
||||||
// In production, allow only your specific, trusted origins
|
|
||||||
let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await;
|
let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await;
|
||||||
// let allowed_origins: Vec<String> = allowed_origins_env.split(",").map(|s| s.to_string()).collect();
|
|
||||||
let allowed_origins: Vec<axum::http::HeaderValue> = allowed_origins_env
|
let allowed_origins: Vec<axum::http::HeaderValue> = allowed_origins_env
|
||||||
.split(",")
|
.split(",")
|
||||||
.map(|s| s.parse::<axum::http::HeaderValue>().unwrap())
|
.map(|s| s.parse::<axum::http::HeaderValue>().unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
cors.allow_origin(allowed_origins)
|
cors.allow_origin(allowed_origins)
|
||||||
// cors.allow_origin(vec![""])
|
|
||||||
/*
|
|
||||||
cors.allow_origin(vec![
|
|
||||||
"https://www.your-production-domain.com"
|
|
||||||
.parse::<axum::http::HeaderValue>()
|
|
||||||
.unwrap(),
|
|
||||||
"https://your-production-domain.com".parse().unwrap(),
|
|
||||||
])
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Development (default): Allow localhost origins
|
// Development (default): Allow localhost origins
|
||||||
cors.allow_origin(vec![
|
cors.allow_origin(vec![
|
||||||
"http://localhost:8000".parse().unwrap(),
|
|
||||||
"http://127.0.0.1:8000".parse().unwrap(),
|
|
||||||
"http://localhost:4200".parse().unwrap(),
|
"http://localhost:4200".parse().unwrap(),
|
||||||
"http://127.0.0.1:4200".parse().unwrap(),
|
"http://127.0.0.1:4200".parse().unwrap(),
|
||||||
])
|
])
|
||||||
|
Reference in New Issue
Block a user