use HTTP_PORT env var for webserver port. Defaults to 80 now

This commit is contained in:
Niklas Kapelle 2025-04-28 14:20:06 +02:00
parent c91ec8076e
commit 727d801849
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -1,9 +1,10 @@
use log::{error, info};
use log::{error, info, warn};
use rocket::http::Status;
use rocket::{Config, State};
use rocket::{get, http::ContentType, response::content::RawHtml, routes};
use rust_embed::Embed;
use std::borrow::Cow;
use std::env;
use std::ffi::OsStr;
use std::sync::Arc;
use tokio::sync::Mutex;
@ -15,9 +16,17 @@ use crate::id_store::IDStore;
struct Asset;
pub async fn start_webserver(store: Arc<Mutex<IDStore>>) -> Result<(), rocket::Error> {
let port = match env::var("HTTP_PORT") {
Ok(port) => port.parse().unwrap_or_else(|_| {
warn!("Failed to parse HTTP_PORT. Using default 80");
80
}),
Err(_) => 80,
};
let config = Config {
address: "0.0.0.0".parse().unwrap(), // Listen on all interfaces
port: 8000,
port,
..Config::default()
};