Skip to content

Commit 4fd7a0e

Browse files
committed
conduit-axum: Add router argument to Server::serve() fn
1 parent 5438707 commit 4fd7a0e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

conduit-axum/examples/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ use std::thread::sleep;
1212
async fn main() {
1313
tracing_subscriber::fmt::init();
1414

15+
let router = axum::Router::new();
16+
1517
let app = build_conduit_handler();
1618
let addr = ([127, 0, 0, 1], 12345).into();
1719

18-
Server::serve(&addr, app).await;
20+
Server::serve(&addr, router, app).await;
1921
}
2022

2123
fn build_conduit_handler() -> impl Handler {

conduit-axum/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
//!
2020
//! #[tokio::main]
2121
//! async fn main() {
22+
//! let router = axum::Router::new();
23+
//!
2224
//! let app = build_conduit_handler();
2325
//! let addr = ([127, 0, 0, 1], 12345).into();
24-
//! let server = Server::serve(&addr, app);
26+
//! let server = Server::serve(&addr, router, app);
2527
//!
2628
//! server.await;
2729
//! }

conduit-axum/src/server.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ impl Server {
1414
/// `tokio::Runtime` it is not possible to furter configure the `hyper::Server`. If more
1515
/// control, such as configuring a graceful shutdown is necessary, then call
1616
/// `Service::from_blocking` instead.
17-
pub fn serve<H: conduit::Handler>(addr: &SocketAddr, handler: H) -> impl Future {
18-
let router = axum::Router::new().conduit_fallback(handler);
17+
pub fn serve<H: conduit::Handler>(
18+
addr: &SocketAddr,
19+
router: axum::Router,
20+
handler: H,
21+
) -> impl Future {
22+
let router = router.conduit_fallback(handler);
1923
let make_service = router.into_make_service_with_connect_info::<SocketAddr>();
2024

2125
hyper::Server::bind(addr).serve(make_service)

0 commit comments

Comments
 (0)