diff options
| author | gennyble <gen@nyble.dev> | 2026-09-24 01:52:48 -0500 |
|---|---|---|
| committer | gennyble <gen@nyble.dev> | 2026-09-24 01:52:48 -0500 |
| commit | f2a9bc39cb9aa8a9d9e186bfd71dfd2405fe1ab6 (patch) | |
| tree | 9a5fdc35930ce7d0a039fe5eae154555cf0231fb /splorm/src/handler/mod.rs | |
| parent | 32cbf8332bdaafae8c0934ff2ab45048bc8f2361 (diff) | |
splorm, meow
Diffstat (limited to 'splorm/src/handler/mod.rs')
| -rw-r--r-- | splorm/src/handler/mod.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/splorm/src/handler/mod.rs b/splorm/src/handler/mod.rs index 95c7e00..edf86f9 100644 --- a/splorm/src/handler/mod.rs +++ b/splorm/src/handler/mod.rs @@ -3,16 +3,17 @@ use std::sync::Arc; use axum::{ Extension, RequestExt, body::Body, - extract::{Path, Request}, + extract::{Path, Request, State}, middleware::Next, response::Response, }; use sessionhash::RequestContext; +pub mod api; mod staticfile; mod templated; -use crate::{RuntimeError, config::Settings, fs::RequestPath}; +use crate::{RuntimeError, config::Settings, fs::RequestPath, state::SplormState}; /// Log runtime errors using a middleware layer. Very much based on the [axum /// error_handling example][axum_errorhandling] @@ -32,16 +33,18 @@ pub async fn log_errors(mut request: Request, next: Next) -> Response { /// GET / pub async fn index( + State(state): State<SplormState>, Extension(settings): Extension<Settings>, ctx: RequestContext, ) -> Result<Response, RuntimeError> { tracing::info!("{ctx} GET /"); let rqp = RequestPath::verify_safe(settings.root(), "home.html")?; - templated::send_file(rqp, &settings).await + templated::send_file(rqp, state, &settings).await } /// GET /{*path} pub async fn static_path( + State(state): State<SplormState>, Extension(settings): Extension<Settings>, Path(path): Path<String>, ctx: RequestContext, @@ -55,7 +58,7 @@ pub async fn static_path( if rqp.guess_mime().as_ref() == "text/html" { tracing::info!("{ctx} GET /{path}"); - templated::send_file(rqp, &settings).await + templated::send_file(rqp, state, &settings).await } else { staticfile::send_or_stream_file(rqp).await } |
