use hostname instead of internal IP
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-02-16 21:44:00 +01:00
parent fef44a592f
commit b0d1402431
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,6 +1,5 @@
use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder}; use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder};
use askama::Template; use askama::Template;
use std::net::SocketAddr;
use crate::config::Config; use crate::config::Config;
@ -8,7 +7,10 @@ use crate::config::Config;
#[get("/.well-known/security.txt")] #[get("/.well-known/security.txt")]
#[get("/security.txt")] #[get("/security.txt")]
pub async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder { pub async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(get_security(config.get_ref().clone(), req.peer_addr())) HttpResponse::Ok().body(get_security(
config.get_ref().clone(),
req.connection_info().to_owned(),
))
} }
#[derive(Template)] #[derive(Template)]
@ -19,11 +21,11 @@ struct SecurityTemplate {
url: String, url: String,
} }
fn get_security(config: Config, addr: Option<SocketAddr>) -> String { fn get_security(config: Config, info: ConnectionInfo) -> String {
let data = SecurityTemplate { let data = SecurityTemplate {
contact: config.mail.unwrap_or_default(), contact: config.mail.unwrap_or_default(),
pref_lang: config.lang.unwrap_or_default(), pref_lang: config.lang.unwrap_or_default(),
url: format!("{}/.well-known/security.txt", addr.unwrap().ip()), url: format!("{}/.well-known/security.txt", info.host()),
}; };
data.render().unwrap() data.render().unwrap()