03517f8783f117fb1d05d7377ab282398cfdcc32
2 use actix_web
::{web
, middleware
, App
, HttpServer
};
3 use chrono
::prelude
::*;
20 async
fn main() -> std
::io
::Result
<()> {
21 if process_args() { return Ok(()) }
23 std
::env
::set_var("RUST_LOG", "info,actix_web=info");
26 println!("Starting Recipes as web server...");
28 let config
= web
::Data
::new(config
::load());
29 let port
= config
.as_ref().port
;
31 println!("Configuration: {:?}", config
);
33 let db_connection
= web
::Data
::new(db
::Connection
::new().unwrap());
36 HttpServer
::new(move || {
38 .wrap(middleware
::Logger
::default())
39 .wrap(middleware
::Compress
::default())
40 .app_data(db_connection
.clone())
41 .app_data(config
.clone())
42 .service(services
::home_page
)
43 .service(services
::sign_up_get
)
44 .service(services
::sign_up_post
)
45 .service(services
::sign_up_check_email
)
46 .service(services
::sign_up_validation
)
47 .service(services
::sign_in_get
)
48 .service(services
::sign_in_post
)
49 .service(services
::sign_out
)
50 .service(services
::view_recipe
)
51 .service(fs
::Files
::new("/static", "static"))
52 .default_service(web
::to(services
::not_found
))
56 server
.bind(&format!("0.0.0.0:{}", port
))?
.run().await
59 #[derive(Parser, Debug)]
65 fn process_args() -> bool
{
66 let args
= Args
::parse();
69 match db
::Connection
::new() {
71 if let Err(error
) = con
.execute_file("sql/data_test.sql") {
72 eprintln!("{}", error
);
74 // Set the creation datetime to 'now'.
75 con
.execute_sql("UPDATE [User] SET [creation_datetime] = ?1 WHERE [email] = 'paul@test.org'", [Utc
::now()]).unwrap();
78 eprintln!("{}", error
);