Skip to content

Commit 016be2c

Browse files
authored
feat: cors (#129)
Set CORS headers in the relay service
1 parent d55c2d5 commit 016be2c

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ metrics = "0.23.0"
221221
metrics-derive = "0.1.0"
222222

223223
# rpc
224+
tower = "0.4"
225+
tower-http = { version = "0.6", features = ["cors"] }
224226
jsonrpsee = "0.24"
225227

226228
# misc

bin/odyssey/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ alloy-network.workspace = true
1717
alloy-primitives.workspace = true
1818
alloy-provider.workspace = true
1919
alloy-rpc-client.workspace = true
20+
clap = { workspace = true, features = ["derive"] }
2021
odyssey-node.workspace = true
2122
odyssey-wallet.workspace = true
2223
odyssey-walltime.workspace = true
@@ -27,7 +28,6 @@ reth-node-builder.workspace = true
2728
reth-optimism-node = { workspace = true, features = ["js-tracer"] }
2829
reth-optimism-cli.workspace = true
2930
reth-provider.workspace = true
30-
clap = { workspace = true, features = ["derive"] }
3131

3232
[features]
3333
default = ["jemalloc"]

bin/relay/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ reth-tracing.workspace = true
2323
clap = { workspace = true, features = ["derive", "env"] }
2424
url.workspace = true
2525
tokio = { workspace = true, features = ["rt", "macros"] }
26+
tower.workspace = true
27+
tower-http.workspace = true
2628

2729
[features]
2830
default = []

bin/relay/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use jsonrpsee::server::Server;
1111
use odyssey_wallet::{AlloyUpstream, OdysseyWallet, OdysseyWalletApiServer};
1212
use reth_tracing::Tracer;
1313
use std::net::{IpAddr, Ipv4Addr};
14+
use tower::ServiceBuilder;
15+
use tower_http::cors::CorsLayer;
1416
use tracing::info;
1517
use url::Url;
1618

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

5456
// start server
55-
let server = Server::builder().http_only().build((self.address, self.port)).await?;
57+
let server = Server::builder()
58+
.http_only()
59+
.set_http_middleware(ServiceBuilder::new().layer(CorsLayer::permissive()))
60+
.build((self.address, self.port))
61+
.await?;
5662
info!(addr = ?server.local_addr().unwrap(), "Started relay service");
5763

5864
let handle = server.start(rpc);

0 commit comments

Comments
 (0)