mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-17 00:00:16 +02:00
Fix compile time regression by boxing routes internally (#404)
This is a reimplementation of #401 but with the new matchit based router. Fixes #399
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
use axum::{
|
||||
handler::{get, post},
|
||||
routing::BoxRoute,
|
||||
Json, Router,
|
||||
};
|
||||
use tower_http::trace::TraceLayer;
|
||||
@@ -32,7 +31,7 @@ async fn main() {
|
||||
/// Having a function that produces our app makes it easy to call it from tests
|
||||
/// without having to create an HTTP server.
|
||||
#[allow(dead_code)]
|
||||
fn app() -> Router<BoxRoute> {
|
||||
fn app() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(|| async { "Hello, World!" }))
|
||||
.route(
|
||||
@@ -43,7 +42,6 @@ fn app() -> Router<BoxRoute> {
|
||||
)
|
||||
// We can still add middleware
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -59,7 +57,7 @@ mod tests {
|
||||
async fn hello_world() {
|
||||
let app = app();
|
||||
|
||||
// `BoxRoute<Body>` implements `tower::Service<Request<Body>>` so we can
|
||||
// `Router` implements `tower::Service<Request<Body>>` so we can
|
||||
// call it like any tower service, no need to run an HTTP server.
|
||||
let response = app
|
||||
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
|
||||
|
||||
Reference in New Issue
Block a user