From 2056095fb7eace6bd38ee2cb2b1a641ec5e581d3 Mon Sep 17 00:00:00 2001 From: Jack Platten Date: Wed, 29 Apr 2026 21:36:50 -0700 Subject: [PATCH] Update config shapes --- src/main.rs | 44 +++++++++++++++++++++++++++++++------------- src/rss_poller.rs | 6 +++--- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index a2155ec..8901ef3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,10 @@ mod settings; use axum::{ extract::{Path, State}, - http::StatusCode, + http::{ + header::{self}, + HeaderMap, StatusCode, + }, response::IntoResponse, routing::get, Json, Router, @@ -31,7 +34,7 @@ async fn main() -> Result<(), Box> { // Create database pool let pool = PgPoolOptions::new() .max_connections(5) - .connect(&config.get_string("database.url")?) + .connect(&config.get::("database.url")?) .await?; log::info!("Connected to database"); @@ -53,8 +56,8 @@ async fn main() -> Result<(), Box> { .with_state(app_state); // Bind and serve - let address = config.get_string("app.address")?; - let port = config.get_int("app.port")? as u16; + let address = config.get::("app.address")?; + let port = config.get::("app.port")?; let addr = format!("{}:{}", address, port).parse::()?; let listener = tokio::net::TcpListener::bind(&addr).await?; log::info!("Server listening on {}", addr); @@ -147,21 +150,36 @@ enum AppError { impl IntoResponse for AppError { fn into_response(self) -> axum::response::Response { match self { - AppError::NotFound => ( - StatusCode::NOT_FOUND, - Json(json!({ - "status": "fail", - "data": {"message": "Post not found"} - })), - ) - .into_response(), + AppError::NotFound => { + let mut headers = HeaderMap::new(); + headers.insert( + header::CACHE_CONTROL, + header::HeaderValue::from_static("no-store"), + ); + // Return (StatusCode, HeaderMap, Body) so the header is sent. + ( + StatusCode::NOT_FOUND, + headers, + Json(json!({ + "status": "fail", + "data": {"message": "Post not found"} + })), + ) + .into_response() + } } } } -async fn not_found() -> (StatusCode, String) { +async fn not_found() -> impl IntoResponse { + let mut headers = HeaderMap::new(); + headers.insert( + header::CACHE_CONTROL, + header::HeaderValue::from_static("no-store"), + ); ( StatusCode::NOT_FOUND, + headers, "Sorry, that path is not valid.".to_string(), ) } diff --git a/src/rss_poller.rs b/src/rss_poller.rs index 37aaa18..afbb3cd 100644 --- a/src/rss_poller.rs +++ b/src/rss_poller.rs @@ -20,13 +20,13 @@ impl PollerConfig { crate::settings::build_config().map_err(|e| format!("Failed to load config: {}", e))?; let poster_handle = cfg - .get_string("poller.handle") + .get::("poller.handle") .map_err(|_| "ATC_POLLER_HANDLE not set".to_string())?; let target_emoji = cfg - .get_string("poller.emoji") + .get::("poller.emoji") .map_err(|_| "ATC_POLLER_EMOJI not set".to_string())?; let blog_domain = cfg - .get_string("poller.domain") + .get::("poller.domain") .map_err(|_| "ATC_POLLER_DOMAIN not set".to_string())?; Ok(PollerConfig { -- knotmirror 0.0.1