about summary refs log tree commit diff
path: root/splorm/src/handler/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'splorm/src/handler/mod.rs')
-rw-r--r--splorm/src/handler/mod.rs11
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
 	}