Skip to content

Commit 419c844

Browse files
graylikemeclaude
andcommitted
fix: add CORS allow_headers and allow_methods for cross-origin requests
The CorsLayer only set allow_origin but not allow_headers or allow_methods, causing preflight failures for content-type header from roster.battledroids.ru. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cfad412 commit 419c844

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/api/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async fn main() -> anyhow::Result<()> {
7171
// ── CORS ──────────────────────────────────────────────────────────────────
7272
let cors = {
7373
let origins = cfg.allowed_origins_list();
74-
if origins.is_empty() {
74+
let base = if origins.is_empty() {
7575
CorsLayer::new()
7676
} else if origins.iter().any(|o| o == "*") {
7777
CorsLayer::new().allow_origin(Any)
@@ -81,7 +81,9 @@ async fn main() -> anyhow::Result<()> {
8181
.filter_map(|o| o.parse().ok())
8282
.collect();
8383
CorsLayer::new().allow_origin(AllowOrigin::list(parsed))
84-
}
84+
};
85+
base.allow_headers([header::CONTENT_TYPE])
86+
.allow_methods([axum::http::Method::GET, axum::http::Method::POST])
8587
};
8688

8789
// ── Rate limiting (100 req/min burst per IP) ───────────────────────────────

0 commit comments

Comments
 (0)