load port from env variable
This commit is contained in:
parent
78d495cfa2
commit
600093c97d
|
@ -531,6 +531,7 @@ name = "miniqr"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"image",
|
||||
"log",
|
||||
"qrcode",
|
||||
"tokio",
|
||||
"urlencoding",
|
||||
|
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
image = "0.23.0"
|
||||
log = "0.4.20"
|
||||
qrcode = "0.12.0"
|
||||
tokio = { version = "1.33.0", features = ["full"] }
|
||||
urlencoding = "2.1.3"
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -6,6 +6,14 @@ use warp::{Filter, reply::Response};
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
let port = std::env::var("PORT").unwrap_or("80".to_string()).parse::<u16>();
|
||||
if port.is_err() {
|
||||
log::warn!("Could not parse port from environment, falling back to port 80");
|
||||
log::warn!("Port parse error message: {}", port.clone().unwrap_err());
|
||||
}
|
||||
let port = port.unwrap_or(80);
|
||||
|
||||
// Match any request and return hello world!
|
||||
let routes =
|
||||
warp::path::end()
|
||||
|
@ -38,5 +46,6 @@ async fn main() {
|
|||
})
|
||||
);
|
||||
|
||||
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
|
||||
log::info!("Running on http://0.0.0.0:{port}");
|
||||
warp::serve(routes).run(([0, 0, 0, 0], port)).await;
|
||||
}
|
Loading…
Reference in New Issue