Skip to content

Commit

Permalink
fix: rename cors_domain to cors_origins
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Nov 10, 2024
1 parent 67159b8 commit fec8bc1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bin/katana/src/cli/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl NodeArgs {
port: self.server.http_port,
addr: self.server.http_addr,
max_connections: self.server.max_connections,
cors_domain: self.server.http_cors_domain.clone(),
cors_origins: self.server.http_cors_origins.clone(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions bin/katana/src/cli/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct ServerOptions {
/// Comma separated list of domains from which to accept cross origin requests.
#[arg(long = "http.corsdomain")]
#[arg(value_delimiter = ',')]
pub http_cors_domain: Option<Vec<String>>,
pub http_cors_origins: Option<Vec<String>>,

/// Maximum number of concurrent connections allowed.
#[arg(long = "rpc.max-connections", value_name = "COUNT")]
Expand All @@ -87,7 +87,7 @@ impl Default for ServerOptions {
http_addr: DEFAULT_RPC_ADDR,
http_port: DEFAULT_RPC_PORT,
max_connections: DEFAULT_RPC_MAX_CONNECTIONS,
http_cors_domain: None,
http_cors_origins: None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn get_default_test_config(sequencing: SequencingConfig) -> Config {
chain.genesis.sequencer_address = *DEFAULT_SEQUENCER_ADDRESS;

let rpc = RpcConfig {
cors_domain: None,
cors_origins: None,
port: 0,
addr: DEFAULT_RPC_ADDR,
max_connections: DEFAULT_RPC_MAX_CONNECTIONS,
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/node/src/config/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct RpcConfig {
pub port: u16,
pub max_connections: u32,
pub apis: HashSet<ApiKind>,
pub cors_domain: Option<Vec<String>>,
pub cors_origins: Option<Vec<String>>,
}

impl RpcConfig {
Expand All @@ -37,7 +37,7 @@ impl RpcConfig {
impl Default for RpcConfig {
fn default() -> Self {
Self {
cors_domain: None,
cors_origins: None,
addr: DEFAULT_RPC_ADDR,
port: DEFAULT_RPC_PORT,
max_connections: DEFAULT_RPC_MAX_CONNECTIONS,
Expand Down
27 changes: 14 additions & 13 deletions crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,20 @@ pub async fn spawn<EF: ExecutorFactory>(
.allow_methods([Method::POST, Method::GET])
.allow_headers([hyper::header::CONTENT_TYPE, "argent-client".parse().unwrap(), "argent-version".parse().unwrap()]);

let cors = config.cors_domain.clone().map(|allowed_origins| match allowed_origins.as_slice() {
[origin] if origin == "*" => cors.allow_origin(AllowOrigin::mirror_request()),
origins => cors.allow_origin(
origins
.iter()
.map(|o| {
let _ = o.parse::<Uri>().expect("Invalid URI");

o.parse().expect("Invalid origin")
})
.collect::<Vec<_>>(),
),
});
let cors =
config.cors_origins.clone().map(|allowed_origins| match allowed_origins.as_slice() {
[origin] if origin == "*" => cors.allow_origin(AllowOrigin::mirror_request()),
origins => cors.allow_origin(
origins
.iter()
.map(|o| {
let _ = o.parse::<Uri>().expect("Invalid URI");

o.parse().expect("Invalid origin")
})
.collect::<Vec<_>>(),
),
});

let middleware = tower::ServiceBuilder::new()
.option_layer(cors)
Expand Down

0 comments on commit fec8bc1

Please sign in to comment.