From c3d4afe71e05fcd95c45e8268468489da6a0b38c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 21 Feb 2023 14:38:32 -0500 Subject: [PATCH] allow port env --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ace9968..817f8ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use tracing::{error, info, metadata::LevelFilter}; use tracing_subscriber::{ filter::filter_fn, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer, }; +use std::env; use types::extract::RequestIp; use crate::public::docs; @@ -73,7 +74,13 @@ async fn main() { .layer(CookieManagerLayer::new()) .layer(DefaultBodyLimit::max(512_000)); - let Ok(addr) = "[::]:8080".parse::() else { + let port: u16 = env::var("PORT") + .unwrap_or_else(|_| String::new()) + .parse::() + .unwrap_or(8080); + + let Ok(addr) = format!("[::]:{port}") + .parse::() else { error!("Failed to parse port binding"); exit(1) };