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
Commit 1a2e951a authored by peterrabbit's avatar peterrabbit
Browse files

website mutex

parent 8b8218a3
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ mod testing; ...@@ -5,7 +5,7 @@ mod testing;
mod tls_config; mod tls_config;
mod website; mod website;
use actix_files::Files; use actix_files::Files;
use actix_web::{App, HttpServer}; use actix_web::{web, App, HttpServer};
use actix_web_lab::middleware::RedirectHttps; use actix_web_lab::middleware::RedirectHttps;
use app::AppState; use app::AppState;
use static_files::StaticFilesManager; use static_files::StaticFilesManager;
...@@ -31,19 +31,20 @@ async fn main() -> std::io::Result<()> { ...@@ -31,19 +31,20 @@ async fn main() -> std::io::Result<()> {
let srv_conf = tls_config(&app_state.config); let srv_conf = tls_config(&app_state.config);
let static_dir = static_files_manager.dir.clone(); let static_dir = static_files_manager.dir.clone();
let mut_static_files_manager = let mut_static_files_manager = web::Data::new(std::sync::Mutex::new(static_files_manager));
actix_web::web::Data::new(std::sync::Mutex::new(static_files_manager));
let app_state = actix_web::web::Data::new(std::sync::Mutex::new(app_state)); let app_state = web::Data::new(std::sync::Mutex::new(app_state));
let mut_website = web::Data::new(std::sync::Mutex::new(website));
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
.wrap(actix_web::middleware::Logger::default()) .wrap(actix_web::middleware::Logger::default())
.wrap(actix_web::middleware::Compress::default()) .wrap(actix_web::middleware::Compress::default())
.wrap(RedirectHttps::default().to_port(port_tls)) .wrap(RedirectHttps::default().to_port(port_tls))
.app_data(actix_web::web::Data::clone(&app_state)) .app_data(web::Data::clone(&app_state))
.app_data(actix_web::web::Data::clone(&mut_static_files_manager)) .app_data(web::Data::clone(&mut_static_files_manager))
.app_data(actix_web::web::Data::new(website.clone())) .app_data(web::Data::clone(&mut_website))
.service(Files::new("/static/", &static_dir)) .service(Files::new("/static/", &static_dir))
.service(service::files::favicon) .service(service::files::favicon)
.service(service::page) .service(service::page)
......
...@@ -3,8 +3,13 @@ use actix_web::{get, web, HttpResponse, Responder}; ...@@ -3,8 +3,13 @@ use actix_web::{get, web, HttpResponse, Responder};
use std::path::PathBuf; use std::path::PathBuf;
#[get("/{pth:.*}")] #[get("/{pth:.*}")]
pub async fn page(website: web::Data<WebSite>, pth: web::Path<PathBuf>) -> impl Responder { 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(); let pth = pth.into_inner();
match website.get_page_by_url(&pth) { match website.get_page_by_url(&pth) {
Some(page) => HttpResponse::Ok().body(page.html.to_string()), Some(page) => HttpResponse::Ok().body(page.html.to_string()),
None => HttpResponse::NotFound().body(format!("Not found {}", pth.display())), None => HttpResponse::NotFound().body(format!("Not found {}", pth.display())),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment