X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=backend%2Fsrc%2Fmain.rs;h=b483ce26cab7823e5f28df6f66af397fdd2229b7;hb=4fbc599d074180920b20ee46e80cc0d3669a4129;hp=037650771f26c9fe8e2d0c2db0fbc7273a5961e8;hpb=e2e54b8f43015738af860b005825dc809f5275ab;p=recipes.git diff --git a/backend/src/main.rs b/backend/src/main.rs index 0376507..b483ce2 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -4,14 +4,14 @@ use std::{fs::File, env::args}; use actix_files as fs; use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpResponse, HttpRequest, web::Query}; -use askama::Template; -use listenfd::ListenFd; +use askama_actix::Template; use ron::de::from_reader; use serde::Deserialize; use itertools::Itertools; mod consts; +mod model; mod db; #[derive(Template)] @@ -39,7 +39,6 @@ async fn home_page(req: HttpRequest) -> impl Responder { #[get("/recipe/view/{id}")] async fn view_page(req: HttpRequest, path: web::Path<(i32,)>) -> impl Responder { - panic!("ERROR"); ViewRecipeTemplate { recipes: vec![ db::Recipe { title: String::from("Saumon en croûte feuilletée"), id: 1 }, db::Recipe { title: String::from("Croissant au jambon"), id: 2 } ], current_recipe: db::Recipe { title: String::from("Saumon en croûte feuilletée"), id: 1 } } } @@ -54,10 +53,13 @@ fn get_exe_name() -> String { first_arg[first_arg.rfind(sep).unwrap()+1..].to_string() } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { if process_args() { return Ok(()) } + std::env::set_var("RUST_LOG", "actix_web=debug"); + env_logger::init(); + println!("Starting Recipes as web server..."); let config: Config = { @@ -74,11 +76,11 @@ async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); - let mut listenfd = ListenFd::from_env(); let mut server = HttpServer::new( || { App::new() + .wrap(middleware::Logger::default()) .wrap(middleware::Compress::default()) .service(home_page) .service(view_page) @@ -86,12 +88,7 @@ async fn main() -> std::io::Result<()> { } ); - server = - if let Some(l) = listenfd.take_tcp_listener(0).unwrap() { - server.listen(l).unwrap() - } else { - server.bind(&format!("0.0.0.0:{}", config.port)).unwrap() - }; + server = server.bind(&format!("0.0.0.0:{}", config.port)).unwrap(); server.run().await } @@ -108,7 +105,10 @@ fn process_args() -> bool { print_usage(); return true } else if args.iter().any(|arg| arg == "--test") { - let db_connection = db::Connection::new(); + match db::Connection::new() { + Ok(_) => (), + Err(error) => println!("Error: {:?}", error) + } return true }