Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
page.rs 530 B
Newer Older
use crate::website::WebSite;
use actix_web::{get, web, HttpResponse, Responder};
use std::path::PathBuf;

#[get("/{pth:.*}")]
peterrabbit's avatar
peterrabbit committed
pub async fn page(
    website: web::Data<std::sync::Mutex<WebSite>>,
    pth: web::Path<PathBuf>,
) -> impl Responder {
    let website = website.lock().unwrap();
    let pth = pth.into_inner();
peterrabbit's avatar
peterrabbit committed

    match website.get_page_by_url(&pth) {
peterrabbit's avatar
peterrabbit committed
        Some(page) => HttpResponse::Ok().body(page.html.to_string()),
        None => HttpResponse::NotFound().body(format!("Not found {}", pth.display())),
    }
}