diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-10-22 17:44:38 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-10-22 17:44:38 -0400 |
commit | 99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac (patch) | |
tree | 15e19324332173405fc7544af2c17195d7b05ff1 /dichroism/src/main.rs | |
parent | 76a782599b4ecc4ecb9b0ce7acc6420ed9e1ec8e (diff) | |
download | theglassyladies-99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac.tar.xz theglassyladies-99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac.zip |
Added product migration, better organization of DTOs, Entities, and
Domain Models. Also made config loading/photo generation easier.
Diffstat (limited to 'dichroism/src/main.rs')
-rw-r--r-- | dichroism/src/main.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/dichroism/src/main.rs b/dichroism/src/main.rs index fb5e2c8..5ecd9a4 100644 --- a/dichroism/src/main.rs +++ b/dichroism/src/main.rs @@ -4,7 +4,7 @@ extern crate serde; extern crate diesel; use actix_web::{App, HttpServer}; -use config::Config; +use config::CONFIG_INSTANCE as CONFIG; use diesel::prelude::SqliteConnection; use diesel::r2d2::ConnectionManager; use diesel::r2d2::Pool; @@ -13,10 +13,11 @@ use result::Result; mod config; mod constants; +mod dtos; +mod entities; mod error; mod handlers; mod models; -mod photo_repo; mod product_repo; mod result; mod schema; @@ -24,18 +25,13 @@ mod types; #[actix_web::main] async fn main() -> Result<()> { - // Gather config. - let config = Config::from_toml()?; - let bind_addr = config.bind_addr; - // Initialize DB connection pool. - let manager = ConnectionManager::<SqliteConnection>::new(&config.db_url); + let manager = ConnectionManager::<SqliteConnection>::new(&CONFIG.db_url); let pool = Pool::builder().build(manager)?; // Initialize application server. let mut server = HttpServer::new(move || { App::new() - .data(config.clone()) .data(pool.clone()) .service(handlers::hello) .service(handlers::get_products) @@ -43,16 +39,16 @@ async fn main() -> Result<()> { .service(handlers::create_product) }); + // If using listenfd, bind to it instead of the configured address to allow for cargo watch + // auto-reloading let mut listenfd = ListenFd::from_env(); server = if let Some(l) = listenfd .take_tcp_listener(0) .expect("Unable to grab TCP listener!") { - // If using listenfd, use it to allow for cargo watch auto-reloading. server.listen(l)? } else { - // Bind to config for release. - server.bind(bind_addr)? + server.bind(CONFIG.bind_addr)? }; Ok(server.run().await?) |