Compare commits
6 Commits
main
...
92f24d4c11
Author | SHA1 | Date | |
---|---|---|---|
92f24d4c11
|
|||
80cbaeb419
|
|||
6ad5b52cf3
|
|||
8cf991b31d
|
|||
975e63bf84
|
|||
2c03264772
|
@@ -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
|
||||
|
@@ -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
|
||||
|
46
Cargo.lock
generated
46
Cargo.lock
generated
@@ -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",
|
||||
@@ -775,8 +786,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",
|
||||
@@ -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"
|
||||
|
@@ -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"] }
|
||||
@@ -21,7 +22,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" }
|
||||
|
@@ -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;
|
||||
|
54
src/main.rs
54
src/main.rs
@@ -45,6 +45,59 @@ 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()
|
||||
.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<String> = allowed_origins_env.split(",").map(|s| s.to_string()).collect();
|
||||
let allowed_origins: Vec<axum::http::HeaderValue> = allowed_origins_env.split(",").map(|s| s.parse::<axum::http::HeaderValue>().unwrap()).collect();
|
||||
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
|
||||
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(),
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn routes() -> Router {
|
||||
// build our application with a route
|
||||
Router::new()
|
||||
@@ -72,6 +125,7 @@ mod init {
|
||||
callers::endpoints::REFRESH_TOKEN,
|
||||
post(callers::login::endpoint::refresh_token),
|
||||
)
|
||||
.layer(cors::configure_cors().await)
|
||||
}
|
||||
|
||||
pub async fn app() -> Router {
|
||||
|
Reference in New Issue
Block a user