Skip to content

Commit

Permalink
feat: cors
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Jan 10, 2025
1 parent d55c2d5 commit 7d86b70
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 2 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 @@ -221,6 +221,8 @@ metrics = "0.23.0"
metrics-derive = "0.1.0"

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

# misc
Expand Down
2 changes: 1 addition & 1 deletion bin/odyssey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ alloy-network.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
clap = { workspace = true, features = ["derive"] }
odyssey-node.workspace = true
odyssey-wallet.workspace = true
odyssey-walltime.workspace = true
Expand All @@ -27,7 +28,6 @@ reth-node-builder.workspace = true
reth-optimism-node = { workspace = true, features = ["js-tracer"] }
reth-optimism-cli.workspace = true
reth-provider.workspace = true
clap = { workspace = true, features = ["derive"] }

[features]
default = ["jemalloc"]
Expand Down
2 changes: 2 additions & 0 deletions bin/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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

[features]
default = []
Expand Down
8 changes: 7 additions & 1 deletion bin/relay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 tracing::info;
use url::Url;

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

// start server
let server = Server::builder().http_only().build((self.address, self.port)).await?;
let server = Server::builder()
.http_only()
.set_http_middleware(ServiceBuilder::new().layer(CorsLayer::permissive()))
.build((self.address, self.port))
.await?;
info!(addr = ?server.local_addr().unwrap(), "Started relay service");

let handle = server.start(rpc);
Expand Down

0 comments on commit 7d86b70

Please sign in to comment.