We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
axum
1 parent ac3856a commit 04a9964Copy full SHA for 04a9964
src/middleware/app.rs
@@ -1,4 +1,8 @@
1
use super::prelude::*;
2
+use axum::extract::State;
3
+use axum::middleware::Next;
4
+use axum::response::Response;
5
+use http::Request;
6
7
use crate::app::AppState;
8
@@ -20,6 +24,17 @@ impl Middleware for AppMiddleware {
20
24
}
21
25
22
26
27
+/// `axum` middleware that injects the `AppState` instance into the `Request` extensions.
28
+pub async fn add_app_state_extension<B>(
29
+ State(app_state): State<AppState>,
30
+ mut request: Request<B>,
31
+ next: Next<B>,
32
+) -> Response {
33
+ request.extensions_mut().insert(app_state);
34
+
35
+ next.run(request).await
36
+}
37
23
38
/// Adds an `app()` method to the `Request` type returning the global `App` instance
39
pub trait RequestApp {
40
fn app(&self) -> &AppState;
0 commit comments