summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 370b9a4..cf87858 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,17 +1,30 @@
+use std::str::FromStr;
+
use actix_web::App;
use actix_web::HttpServer;
use actix_web::middleware::Logger;
+use anyhow::Context;
mod frontend;
mod backend;
#[actix_web::main]
-async fn main() -> std::io::Result<()> {
+async fn main() -> anyhow::Result<()> {
if let Err(std::env::VarError::NotPresent) = std::env::var("RUST_LOG") {
std::env::set_var("RUST_LOG", "actix_web=info");
}
env_logger::init();
+ let bind = match std::env::var("WATER_LEVELS_HOST") {
+ Ok(var) => var,
+ Err(e) => anyhow::bail!("WATER_LEVELS_HOST not available: {:?}", e),
+ };
+
+ let port = match std::env::var("WATER_LEVELS_PORT") {
+ Ok(var) => u16::from_str(&var).context("Parsing port to u16")?,
+ Err(e) => anyhow::bail!("WATER_LEVELS_PORT not available: {:?}", e),
+ };
+
HttpServer::new(|| {
App::new()
.wrap(Logger::default())
@@ -20,7 +33,8 @@ async fn main() -> std::io::Result<()> {
.service(crate::frontend::make_landscape)
.service(crate::frontend::calculate)
})
- .bind(("127.0.0.1", 8080))?
+ .bind((bind, port))?
.run()
.await
+ .map_err(anyhow::Error::from)
}