Skip to content

Commit c82bfa8

Browse files
ghubertpaloDamien LACHAUME / PALO-IT
authored andcommitted
add CORS configuration
1 parent 5375375 commit c82bfa8

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

mithril-aggregator-fake/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ serde_json = "1.0.108"
2020
signal-hook = "0.3.17"
2121
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
2222
tokio = { version = "1.35.0", features = ["full"] }
23-
tower-http = { version = "0.5.0", features = ["trace"] }
23+
tower-http = { version = "0.5.0", features = ["trace", "cors"] }
2424
tracing = "0.1.40"
2525
tracing-subscriber = "0.3.18"
2626

2727
[dev-dependencies]
28-
reqwest = "0.11.23"
29-
mithril-common = { "path" = "../mithril-common", features = ["test_tools", "random"] }
3028
http = "0.2.9"
29+
mithril-common = { "path" = "../mithril-common", features = ["test_tools", "random"] }
30+
reqwest = "0.11.23"

mithril-aggregator-fake/src/application.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use futures::stream::StreamExt;
1010
use signal_hook::consts::*;
1111
use signal_hook_tokio::Signals;
1212
use tower_http::{
13+
cors::CorsLayer,
1314
trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer},
1415
LatencyUnit,
1516
};
@@ -93,6 +94,7 @@ impl Application {
9394
post(handlers::statistics),
9495
)
9596
.with_state(shared_state)
97+
.layer(CorsLayer::permissive())
9698
.layer(middleware::from_fn(handlers::set_json_app_header))
9799
.layer(
98100
TraceLayer::new_for_http()
@@ -149,7 +151,7 @@ mod tests {
149151
const BASE_URL: &str = "http://127.0.0.1:PORT/aggregator";
150152

151153
// tester
152-
async fn test<T>(fn_test: JoinHandle<StdResult<()>>, port: u16) {
154+
async fn test(fn_test: JoinHandle<StdResult<()>>, port: u16) {
153155
let params = CliArguments {
154156
data_directory: None,
155157
verbose: 0,
@@ -193,7 +195,7 @@ mod tests {
193195
Ok(())
194196
});
195197

196-
test::<StdResult<()>>(task, PORT).await;
198+
test(task, PORT).await;
197199
}
198200

199201
#[tokio::test]
@@ -222,7 +224,7 @@ mod tests {
222224
Ok(())
223225
});
224226

225-
test::<StdResult<()>>(task, PORT).await;
227+
test(task, PORT).await;
226228
}
227229

228230
#[tokio::test]
@@ -251,7 +253,7 @@ mod tests {
251253
Ok(())
252254
});
253255

254-
test::<StdResult<()>>(task, PORT).await;
256+
test(task, PORT).await;
255257
}
256258

257259
#[tokio::test]
@@ -287,7 +289,7 @@ mod tests {
287289
Ok(())
288290
});
289291

290-
test::<StdResult<()>>(task, PORT).await;
292+
test(task, PORT).await;
291293
}
292294

293295
#[tokio::test]
@@ -307,7 +309,7 @@ mod tests {
307309
Ok(())
308310
});
309311

310-
test::<StdResult<()>>(task, PORT).await;
312+
test(task, PORT).await;
311313
}
312314

313315
#[tokio::test]
@@ -339,7 +341,7 @@ mod tests {
339341
Ok(())
340342
});
341343

342-
test::<StdResult<()>>(task, PORT).await;
344+
test(task, PORT).await;
343345
}
344346

345347
#[tokio::test]
@@ -362,7 +364,7 @@ mod tests {
362364
Ok(())
363365
});
364366

365-
test::<StdResult<()>>(task, PORT).await;
367+
test(task, PORT).await;
366368
}
367369

368370
#[tokio::test]
@@ -394,7 +396,7 @@ mod tests {
394396
Ok(())
395397
});
396398

397-
test::<StdResult<()>>(task, PORT).await;
399+
test(task, PORT).await;
398400
}
399401

400402
#[tokio::test]
@@ -414,7 +416,7 @@ mod tests {
414416
Ok(())
415417
});
416418

417-
test::<StdResult<()>>(task, PORT).await;
419+
test(task, PORT).await;
418420
}
419421

420422
#[tokio::test]
@@ -443,6 +445,6 @@ mod tests {
443445
Ok(())
444446
});
445447

446-
test::<StdResult<()>>(task, PORT).await;
448+
test(task, PORT).await;
447449
}
448450
}

0 commit comments

Comments
 (0)