Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more explicit cors policy #133

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ metrics = "0.23.0"
metrics-derive = "0.1.0"

# rpc
jsonrpsee = "0.24"
hyper = "1.5"
tower = "0.4"
tower-http = { version = "0.6", features = ["cors"] }
jsonrpsee = "0.24"

# misc
clap = "4"
Expand Down
13 changes: 7 additions & 6 deletions bin/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ description = "Odyssey Relay is an EIP-7702 native transaction batcher and spons
workspace = true

[dependencies]
alloy-signer-local.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
odyssey-wallet.workspace = true
alloy-signer-local.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
eyre.workspace = true
hyper.workspace = true
jsonrpsee = { workspace = true, features = ["server"] }
tracing.workspace = true
odyssey-wallet.workspace = true
reth-tracing.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
url.workspace = true
tokio = { workspace = true, features = ["rt", "macros"] }
tower.workspace = true
tower-http.workspace = true
tower.workspace = true
tracing.workspace = true
url.workspace = true

[features]
default = []
Expand Down
9 changes: 7 additions & 2 deletions bin/relay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use alloy_rpc_client::RpcClient;
use alloy_signer_local::PrivateKeySigner;
use clap::Parser;
use eyre::Context;
use hyper::Method;
use jsonrpsee::server::Server;
use odyssey_wallet::{AlloyUpstream, OdysseyWallet, OdysseyWalletApiServer};
use reth_tracing::Tracer;
use std::net::{IpAddr, Ipv4Addr};
use tower::ServiceBuilder;
use tower_http::cors::CorsLayer;
use tower_http::cors::{Any, CorsLayer};
use tracing::info;
use url::Url;

Expand Down Expand Up @@ -54,9 +55,13 @@ impl Args {
let rpc = OdysseyWallet::new(AlloyUpstream::new(provider), chain_id).into_rpc();

// start server
let cors = CorsLayer::new()
.allow_methods([Method::POST])
.allow_origin(Any)
.allow_headers([hyper::header::CONTENT_TYPE]);
let server = Server::builder()
.http_only()
.set_http_middleware(ServiceBuilder::new().layer(CorsLayer::permissive()))
.set_http_middleware(ServiceBuilder::new().layer(cors))
.build((self.address, self.port))
.await?;
info!(addr = ?server.local_addr().unwrap(), "Started relay service");
Expand Down
Loading