Skip to content

Commit

Permalink
workers: Debug CORS
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Nov 1, 2023
1 parent 9fb7115 commit a82633a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions workers/api-server/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ impl<

let req_body: Req = deserialized.unwrap();

let allowed_methods = vec![Method::GET, Method::POST].into_iter().collect_vec();

// Combine the allowed methods into a comma separated string
let allowed_methods_str = allowed_methods
.iter()
.map(|method| method.as_str())
.join(",");
dbg!(allowed_methods_str.clone());

// Forward to the typed handler
let res = self.handle_typed(headers, req_body, url_params).await;
if let Ok(resp) = res {
Expand All @@ -136,6 +145,8 @@ impl<
// leak from cross-origin requests.
Response::builder()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "*")
.header("Access-Control-Allow-Methods", allowed_methods_str)
.body(Body::from(serde_json::to_vec(&resp).unwrap()))
.unwrap()
} else {
Expand Down

0 comments on commit a82633a

Please sign in to comment.