diff --git a/Cargo.toml b/Cargo.toml index 4bed7d14f..d57433f96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,7 +152,7 @@ rocket = { version = "0.4", optional = true } async-std = { version = "1.10.0", features = ["attributes"] } httpmock = "0.6.6" tokio = { version = "1.24.1", features = ["rt", "macros"] } -axum = { version = "0.6.18", features = ["macros"] } +axum = { version = "0.7.4", features = ["macros"] } async-trait = "0.1" actix-web = "4.2.1" diff --git a/examples/webhook-axum.rs b/examples/webhook-axum.rs index e102a135e..27e985c59 100644 --- a/examples/webhook-axum.rs +++ b/examples/webhook-axum.rs @@ -12,9 +12,9 @@ //! stripe trigger checkout.session.completed //! ``` -use std::net::SocketAddr; - use axum::{ + async_trait, + body::Body, extract::FromRequest, http::{Request, StatusCode}, response::{IntoResponse, Response}, @@ -30,25 +30,24 @@ async fn main() { // build our application with a route let app = Router::new().route("/stripe_webhooks", post(handle_webhook)); - // run our app with hyper - // `axum::Server` is a re-export of `hyper::Server` - let addr = SocketAddr::from(([127, 0, 0, 1], 4242)); - println!("listening on {}", addr); - axum::Server::bind(&addr).serve(app.into_make_service()).await.unwrap(); + let listener = tokio::net::TcpListener::bind("127.0.0.1:4242").await.unwrap(); + + println!("listening on {}", listener.local_addr().unwrap()); + + axum::serve(listener, app).await.unwrap(); } struct StripeEvent(Event); -#[async_trait::async_trait] -impl FromRequest for StripeEvent +#[async_trait] +impl FromRequest for StripeEvent where - String: FromRequest, - B: Send + 'static, + String: FromRequest, S: Send + Sync, { type Rejection = Response; - async fn from_request(req: Request, state: &S) -> Result { + async fn from_request(req: Request, state: &S) -> Result { let signature = if let Some(sig) = req.headers().get("stripe-signature") { sig.to_owned() } else {