Skip to content

Commit 388b9b8

Browse files
committed
fix(backend): allow local frontend cors
1 parent bf55963 commit 388b9b8

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

apps/backend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ serde_json = "1.0"
1111
tempfile = "3.12"
1212
thiserror = "1.0"
1313
tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] }
14-
tower-http = { version = "0.5", features = ["trace"] }
14+
tower-http = { version = "0.5", features = ["trace", "cors"] }
1515
tracing = "0.1"
1616
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
1717
uuid = { version = "1.8", features = ["v4"] }

apps/backend/src/infra/http/router.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ use crate::app::ScanService;
22
use crate::infra::http::handlers::{health, scan_bundle};
33
use axum::routing::{get, post};
44
use axum::Router;
5+
use axum::http::{HeaderValue, Method};
6+
use tower_http::cors::{Any, CorsLayer};
57
use tower_http::trace::TraceLayer;
68

79
pub fn build_router(scan_service: ScanService) -> Router {
10+
let cors = CorsLayer::new()
11+
.allow_origin([
12+
HeaderValue::from_static("http://localhost:3000"),
13+
HeaderValue::from_static("http://127.0.0.1:3000"),
14+
])
15+
.allow_methods([Method::GET, Method::POST])
16+
.allow_headers(Any);
17+
818
Router::new()
919
.route("/healthz", get(health))
1020
.route("/api/v1/scan", post(scan_bundle))
1121
.with_state(scan_service)
22+
.layer(cors)
1223
.layer(TraceLayer::new_for_http())
1324
}

0 commit comments

Comments
 (0)