allow port env

This commit is contained in:
Tyler Murphy 2023-02-21 14:38:32 -05:00
parent 7ae392ad76
commit c3d4afe71e
No known key found for this signature in database
GPG key ID: 04CC7A6A289B470F

View file

@ -13,6 +13,7 @@ use tracing::{error, info, metadata::LevelFilter};
use tracing_subscriber::{ use tracing_subscriber::{
filter::filter_fn, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer, filter::filter_fn, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer,
}; };
use std::env;
use types::extract::RequestIp; use types::extract::RequestIp;
use crate::public::docs; use crate::public::docs;
@ -73,7 +74,13 @@ async fn main() {
.layer(CookieManagerLayer::new()) .layer(CookieManagerLayer::new())
.layer(DefaultBodyLimit::max(512_000)); .layer(DefaultBodyLimit::max(512_000));
let Ok(addr) = "[::]:8080".parse::<std::net::SocketAddr>() else { let port: u16 = env::var("PORT")
.unwrap_or_else(|_| String::new())
.parse::<u16>()
.unwrap_or(8080);
let Ok(addr) = format!("[::]:{port}")
.parse::<std::net::SocketAddr>() else {
error!("Failed to parse port binding"); error!("Failed to parse port binding");
exit(1) exit(1)
}; };