Skip to content

Commit

Permalink
add localhost to allowed origins
Browse files Browse the repository at this point in the history
  • Loading branch information
ivinjabraham committed Feb 4, 2025
1 parent 1e22635 commit 3d3b983
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ fn build_graphql_schema(

/// Abstraction over making the CORSLayer.
fn setup_cors() -> CorsLayer {
let origins: [HeaderValue; 2] = [
"127.0.0.1".parse().unwrap(),
"https://home.amfoss.in".parse().unwrap(),
];

CorsLayer::new()
// Home should be the only website that accesses the API, bots and scripts do not trigger CORS AFAIK.
// This lets us restrict who has access to what in the API on the Home frontend.
.allow_origin(HeaderValue::from_static("https://home.amfoss.in"))
.allow_origin(origins)
.allow_methods([Method::GET, Method::POST, Method::OPTIONS])
.allow_headers(tower_http::cors::Any)
}

0 comments on commit 3d3b983

Please sign in to comment.