summaryrefslogtreecommitdiff
path: root/src/user/routes/mod.rs
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-06-18 23:52:47 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-06-18 23:52:47 +0200
commitd84ba5cd09b713fac2f193d5c05af7415ea6742d (patch)
tree6ea93d417f329baccaa84f1d557638f54f3f2d37 /src/user/routes/mod.rs
parent4a7fb2c5cf7265c5ef6a78051c1bb73e7d3ef086 (diff)
parent43375bcb875a31ce8c6132ce78552d45f64b261b (diff)
Unify `setup_required` middlewares.
The two middlewares were identical but for the specific `IntoResponse` impl used to generate the response when setup has not been completed. However, unifying them while still using `from_fn_with_state` lead to this horrorshow: .route_layer(middleware::from_fn_with_state( app.clone(), |state, req, next| { setup::middeware::setup_required(UNAVAILABLE, state, req, next) } )) It's a lot to read, and it surfaces the entire signature of a state-driven middleware `fn` into the call site solely to close over one argument (`UNAVAILABLE`). Rather than doing that, I've converted this middleware into a full blown Tower middleware, following <https://docs.rs/axum/latest/axum/middleware/index.html#towerservice-and-pinboxdyn-future>. I considered taking this further and implementing a custom future to remove the allocation for `Box::pin`, but honestly, that allocation isn't hurting anyone and this code already got long enough in the translation. The new API looks like: .route_layer(setup::Required(app.clone())) Or like: .route_layer(setup::Required(app.clone()).with_fallback(RESPONSE)) Part of a broader project to reorganize our routing. This is intended to reduce the number of "why do we have two of these?" questions when the answer isn't very compelling. We had two of these because I needed them to behave slightly differently, and at the time I didn't fully understand how to abstract out that difference. Now I do, thanks to Axum's excellent documentation. Merges unify-setup-required into main.
Diffstat (limited to 'src/user/routes/mod.rs')
0 files changed, 0 insertions, 0 deletions