use crate::{config::Config, template::Infos}; use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder}; use cached::proc_macro::once; use ramhorns::Content; #[routes] #[get("/.well-known/security.txt")] #[get("/security.txt")] pub async fn security(req: HttpRequest, config: web::Data) -> impl Responder { HttpResponse::Ok().body(build_securitytxt( config.get_ref().clone(), req.connection_info().to_owned(), )) } #[derive(Content)] struct SecurityTemplate { contact: String, pref_lang: String, url: String, } #[once(time = 60)] fn build_securitytxt(config: Config, info: ConnectionInfo) -> String { config.tmpl.render( "security.txt", SecurityTemplate { contact: config.fc.mail.unwrap_or_default(), pref_lang: config.fc.lang.unwrap_or_default(), url: format!( "{}://{}/.well-known/security.txt", info.scheme(), info.host() ), }, Infos::default(), ) } #[get("/humans.txt")] pub async fn humans() -> impl Responder { // TODO, see https://humanstxt.org/humans.txt actix_web::web::Redirect::to("/") } #[get("/robots.txt")] pub async fn robots() -> impl Responder { HttpResponse::Ok().body(build_robotstxt()) } #[once(time = 60)] fn build_robotstxt() -> String { // TODO, see https://www.robotstxt.org/orig.html "User-agent: * Allow: /".to_owned() } #[get("/sitemap.xml")] pub async fn sitemap() -> impl Responder { // TODO actix_web::web::Redirect::to("/") }