Skip to content

Commit

Permalink
fix(api): use permissive cors (#361)
Browse files Browse the repository at this point in the history
# What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `cargo fmt`.
  • Loading branch information
montekki committed Jan 19, 2024
1 parent 5d3254a commit dab6780
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ tx-sender = { path = "./tx-sender" }
finalizer = { path = "./finalizer" }
tokio-stream = "0.1.14"
tokio-util = "0.7.10"
tower-http = "0.5.1"
url = "2.5.0"
axum = "0.7.4"
vlog = { path = "./vlog" }
5 changes: 3 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ edition.workspace = true
authors.workspace = true

[dependencies]
axum = "0.7.4"
axum = { workspace = true }
tower-http = { workspace = true, features = ["cors"] }
storage.workspace = true
sqlx.workspace = true
serde.workspace = true
tokio.workspace = true
ethers.workspace = true
ethers.workspace = true
3 changes: 3 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ethers::types::{H256, U256};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use storage::UserWithdrawal;
use tower_http::cors::CorsLayer;

#[derive(Deserialize, Serialize, Clone)]
struct WithdrawalRequest {
Expand All @@ -30,9 +31,11 @@ impl From<UserWithdrawal> for WithdrawalResponse {
}

pub async fn run_server(pool: PgPool) {
let cors_layer = CorsLayer::permissive();
let app = Router::new()
.route("/withdrawals/:from", get(get_withdrawals))
.route("/health", get(health))
.layer(cors_layer)
.with_state(pool);

// run our app with hyper, listening globally on port 3000
Expand Down

0 comments on commit dab6780

Please sign in to comment.