Skip to content

Commit

Permalink
Add cors support to cli serve. Fixes #93 (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Bellamy authored Aug 30, 2022
1 parent 4ead39c commit 267e7b9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,32 @@ impl Cmd {
Arc::new(Mutex::new(HashMap::new()));
let with_transaction_status_map = warp::any().map(move || transaction_status_map.clone());

let routes = warp::post()
let jsonrpc_route = warp::post()
.and(warp::path!("api" / "v1" / "jsonrpc"))
.and(warp::body::json())
.and(with_ledger_file)
.and(with_transaction_status_map)
.and_then(handler);

// Allow access from all remote sites when we are in local sandbox mode. (Always for now)
let cors = warp::cors()
.allow_any_origin()
.allow_credentials(true)
.allow_headers(vec![
"Accept",
"Access-Control-Request-Headers",
"Access-Control-Request-Method",
"Content-Length",
"Content-Type",
"Encoding",
"Origin",
"Referer",
"Sec-Fetch-Mode",
"User-Agent",
])
.allow_methods(vec!["GET", "POST"]);
let routes = jsonrpc_route.with(cors);

let addr: SocketAddr = ([127, 0, 0, 1], self.port).into();
println!("Listening on: {}", addr);
warp::serve(routes).run(addr).await;
Expand Down

0 comments on commit 267e7b9

Please sign in to comment.