Skip to content

Commit

Permalink
fix: CORS part 4 - revelations
Browse files Browse the repository at this point in the history
  • Loading branch information
sargon64 committed Oct 23, 2023
1 parent c1e303b commit 3f9193e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ async fn main() -> anyhow::Result<()> {
std::env::var("TA_WS_URI").unwrap(),
"TA-Relay-TX",
)
.await
.unwrap(),
.await
.unwrap(),
);
let mut ta_con = connection::TAConnection::connect(
std::env::var("TA_WS_URI").unwrap(),
"TA-Relay-RX",
)
.await
.unwrap();
.await
.unwrap();

while let Some(msg) = ta_con.next().await {
let msg = match msg {
Expand Down Expand Up @@ -153,12 +153,13 @@ async fn main() -> anyhow::Result<()> {

let cors = warp::cors()
.allow_any_origin()
.allow_methods(vec!["POST", "GET"])
.allow_methods(vec!["POST", "GET", "OPTIONS"])
.allow_headers(vec![
"User-Agent",
"Sec-Fetch-Mode",
"Referer",
"Origin",
"Content-Type",
"Access-Control-Request-Method",
"Access-Control-Request-Headers",
"Sec-WebSocket-Protocol"
Expand Down Expand Up @@ -189,16 +190,19 @@ async fn main() -> anyhow::Result<()> {
.map(|reply| {
// this is todo in the example, but it's required for the magic websocket magic to work!
warp::reply::with_header(reply, "Sec-WebSocket-Protocol", "graphql-ws")
}))
})
.map(|reply| {
warp::reply::with_header(reply, "Access-Control-Allow-Origin", "*")
})
)
.or(warp::path("graphql").and(graphql_filter))
.with(log)
.with(cors)
)
.run(([0, 0, 0, 0], 8080))
.await;
.run(([0, 0, 0, 0], 8080))
.await;
Ok(())
}

// #[get("/")]
// async fn index() -> impl Responder {
// ""
Expand Down

0 comments on commit 3f9193e

Please sign in to comment.