Microservice to bring 2FA to self hosted PDSes
at feature/admin-rbac 45 lines 1.2 kB view raw
1use axum::{ 2 extract::Path, 3 http::{StatusCode, header}, 4 response::{IntoResponse, Response}, 5}; 6 7use crate::StaticFiles; 8 9/// Serve embedded static files at /admin/static/*path 10pub async fn serve_static(Path(path): Path<String>) -> Response { 11 let file = match StaticFiles::get(&path) { 12 Some(file) => file, 13 None => return StatusCode::NOT_FOUND.into_response(), 14 }; 15 16 let mime_type = mime_from_path(&path); 17 18 ( 19 [ 20 (header::CONTENT_TYPE, mime_type), 21 (header::CACHE_CONTROL, cache_control_value()), 22 ], 23 file.data.to_vec(), 24 ) 25 .into_response() 26} 27 28fn mime_from_path(path: &str) -> &'static str { 29 match path.rsplit('.').next() { 30 Some("css") => "text/css; charset=utf-8", 31 Some("js") => "application/javascript; charset=utf-8", 32 Some("svg") => "image/svg+xml", 33 Some("png") => "image/png", 34 Some("jpg") | Some("jpeg") => "image/jpeg", 35 _ => "application/octet-stream", 36 } 37} 38 39fn cache_control_value() -> &'static str { 40 if cfg!(debug_assertions) { 41 "no-cache" 42 } else { 43 "public, max-age=3600, stale-while-revalidate=86400" 44 } 45}