Skip to content

Commit 27494e0

Browse files
author
copyleftdev
committed
fix(gateway): Add CORS support for cross-origin requests
Added CorsLayer::permissive() middleware to allow requests from localhost:3000 test app to localhost:8080 gateway. This fixes: 'Access-Control-Allow-Origin' header missing error Changes: - Added 'cors' feature to tower-http dependency - Imported CorsLayer - Applied permissive CORS policy (dev mode only)
1 parent f93f124 commit 27494e0

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

crates/scrybe-gateway/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ serde_json = { workspace = true }
1919
tokio = { workspace = true }
2020
axum = { workspace = true }
2121
tower = { workspace = true }
22-
tower-http = { workspace = true }
22+
tower-http = { workspace = true, features = ["trace", "cors"] }
2323
tracing = { workspace = true }
2424
tracing-subscriber = { workspace = true }
2525
http = "1.1"

crates/scrybe-gateway/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use routes::ingest::AppState;
3131
use scrybe_core::{Config, ScrybeError};
3232
use std::net::SocketAddr;
3333
use std::sync::Arc;
34-
use tower_http::trace::TraceLayer;
34+
use tower_http::{cors::CorsLayer, trace::TraceLayer};
3535
use tracing::info;
3636

3737
#[tokio::main]
@@ -55,6 +55,9 @@ async fn main() -> Result<(), ScrybeError> {
5555
// Create application state
5656
let state = Arc::new(AppState::new());
5757

58+
// Configure CORS
59+
let cors = CorsLayer::permissive(); // Allow all origins in dev mode
60+
5861
// Build router with all routes and middleware
5962
let app = Router::new()
6063
// Health check routes (no authentication required)
@@ -63,6 +66,7 @@ async fn main() -> Result<(), ScrybeError> {
6366
// API routes (with authentication and rate limiting)
6467
.merge(routes::ingest_route())
6568
// Global middleware
69+
.layer(cors)
6670
.layer(axum::middleware::from_fn(middleware::security_headers))
6771
.layer(TraceLayer::new_for_http())
6872
.with_state(state);

0 commit comments

Comments
 (0)