Allow use of custom port and bind_addr.

This commit is contained in:
Luke Harding 2024-05-02 19:49:48 -04:00
parent 73c97a2c5a
commit 2bff93ff43

View File

@ -1,13 +1,31 @@
use std::env;
use actix_web::{App, get, HttpResponse, HttpServer, Responder}; use actix_web::{App, get, HttpResponse, HttpServer, Responder};
use crate::util::warn_println;
mod util; mod util;
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
util::print_copyright_notice(); util::print_copyright_notice();
let port = 8000; // Default Server Values
let bind_addr = "127.0.0.1"; let mut port = 8000;
let mut bind_addr = String::from("127.0.0.1");
// If env variable for port or bind_addr is present use that instead of default.
if let Ok(env_port) = env::var("PORT") {
if let Ok(env_port) = env_port.parse::<u16>() {
port = env_port;
} else {
warn_println("Failed to parse PORT env variable using default value.");
}
}
if let Ok(env_addr) = env::var("BIND_ADDR") {
bind_addr = env_addr;
}
util::notice_println(format!("Starting server on {}:{}", bind_addr, port)); util::notice_println(format!("Starting server on {}:{}", bind_addr, port));