From 03ca17fdb509565dd807a8567c24e0f2649c83f5 Mon Sep 17 00:00:00 2001 From: Alphonse Paix Date: Tue, 23 Sep 2025 16:09:15 +0200 Subject: [PATCH] favicon --- assets/favicon.png | Bin 0 -> 874 bytes src/startup.rs | 25 ++++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 assets/favicon.png diff --git a/assets/favicon.png b/assets/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..217fd72d5810d52cb19832ba8a2d1b36168f2004 GIT binary patch literal 874 zcmV-w1C{)VP)PsN2gRvu}ka$V76_y6nh(`~E+)7v)4r2#PUQPMr z6A&{DHbu5CN%0GaI}7#A5?f(uAS@70&4P))oRzhoWcRCXP*lB#L$@Kj6k62L<|dW~ z6l#heB|un^#OlY3Uc&QwD0>IRFX7%BsdH zgPZX%e1PQ3-@%w1(Tbsc;d85;imtFUur~%aM(U8{La^Ty9UTINi$pt32zEeqBY5|M zlEqM31IsT;{cl(rI1mf#I&{FEV%T|2w3h*2w}@6`+z z|GEKeedTklCZrTX<}InY!qR}^=nP00ufyMHXoiU6@Ua<22Ex-1@T^{!UE-Djwbsc| zusIU?`|9*}D(hfLp1cn_gIfmL@aqkegCVpZw6w~f&^tA<-krrG16_eK(Bl`A9=@8T zn>*;m9-Zo5QVo4QH&_h}>4xP{d#(nPEOkBq27wVJs4qEN(*OVf07*qoM6N<$g77Si A`Tzg` literal 0 HcmV?d00001 diff --git a/src/startup.rs b/src/startup.rs index 607e965..875551f 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -1,12 +1,15 @@ use crate::{configuration::Settings, email_client::EmailClient, routes::require_auth, routes::*}; use axum::{ Router, + body::Bytes, extract::MatchedPath, http::Request, middleware, + response::{IntoResponse, Response}, routing::{get, post}, }; use axum_server::tls_rustls::RustlsConfig; +use reqwest::{StatusCode, header}; use secrecy::ExposeSecret; use sqlx::{PgPool, postgres::PgPoolOptions}; use std::{net::TcpListener, sync::Arc, time::Duration}; @@ -124,7 +127,6 @@ pub fn app( .route("/logout", post(logout)) .layer(middleware::from_fn(require_auth)); Router::new() - .nest_service("/assets", ServeDir::new("assets")) .route("/", get(home)) .route("/login", get(get_login).post(post_login)) .route("/health_check", get(health_check)) @@ -134,7 +136,9 @@ pub fn app( .route("/unsubscribe/confirm", get(unsubscribe_confirm)) .route("/posts", get(list_posts)) .route("/posts/{post_id}", get(see_post)) + .route("/favicon.ico", get(favicon)) .nest("/admin", admin_routes) + .nest_service("/assets", ServeDir::new("assets")) .layer( TraceLayer::new_for_http().make_span_with(|request: &Request<_>| { let matched_path = request @@ -156,3 +160,22 @@ pub fn app( .fallback(not_found) .with_state(app_state) } + +pub async fn favicon() -> Response { + match tokio::fs::read("assets/favicon.png").await { + Ok(content) => { + let bytes = Bytes::from(content); + let body = bytes.into(); + Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "image/x-icon") + .header(header::CACHE_CONTROL, "public, max-age=86400") + .body(body) + .unwrap() + } + Err(e) => { + tracing::error!("Error while reading favicon.ico: {}", e); + StatusCode::NOT_FOUND.into_response() + } + } +}