Skip to content

Commit

Permalink
style: better error handling for enviroment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ChecksumDev committed Oct 17, 2023
1 parent adf86fa commit e516b37
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ async fn main() -> Result<()> {
.filename("data/lumen.db")
.create_if_missing(true),
)
.await
.unwrap();
.await?;

// todo: support other databases (mysql, postgresql, etc)
sqlx::migrate!().run(&pool).await.unwrap();
sqlx::migrate!().run(&pool).await?;
let data = Data::new(AppData { pool, storage });

println!("Lumen is running on {}", std::env::var("HOST").unwrap());
let host = match std::env::var("HOST") {
Ok(host) => host,
Err(_) => {
println!("The HOST environment variable is not set, defaulting to 127.0.0.1:8080");
"127.0.0.1:8080".to_string()
}
};

println!("Lumen is running on {}", host);
HttpServer::new(move || {
App::new()
.app_data(data.clone())
Expand All @@ -46,7 +52,7 @@ async fn main() -> Result<()> {
.service(upload)
.service(download)
})
.bind(std::env::var("HOST")?)?
.bind(host)?
.run()
.await?;

Expand Down

0 comments on commit e516b37

Please sign in to comment.