summaryrefslogtreecommitdiff
path: root/dichroism/src/bin
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-10-05 22:05:58 -0400
committerAdam T. Carpenter <atc@53hor.net>2020-10-05 22:05:58 -0400
commit743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d (patch)
tree3d393ff1ffd06d1bf470430b2316f46000794806 /dichroism/src/bin
parentf8bf353073220ce329d8eb347e3574d5793b6d26 (diff)
downloadtheglassyladies-743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d.tar.xz
theglassyladies-743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d.zip
started work on schema, models, and repos
Diffstat (limited to 'dichroism/src/bin')
-rw-r--r--dichroism/src/bin/dichroismd.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/dichroism/src/bin/dichroismd.rs b/dichroism/src/bin/dichroismd.rs
new file mode 100644
index 0000000..2dc059d
--- /dev/null
+++ b/dichroism/src/bin/dichroismd.rs
@@ -0,0 +1,44 @@
+use actix_web::{App, HttpServer};
+use dichroism::config;
+use dichroism::handlers;
+use dichroism::result::Result;
+use diesel::prelude::SqliteConnection;
+use diesel::r2d2::ConnectionManager;
+use diesel::r2d2::Pool;
+use listenfd::ListenFd;
+
+#[actix_web::main]
+async fn main() -> Result<()> {
+ // Gather config.
+ let config = config::Config::new_from_env().await?;
+ 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::create_image)
+ .service(handlers::get_products)
+ });
+
+ 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)?
+ };
+
+ Ok(server.run().await?)
+}