Add PORT and BIND_ADDR envs to .env

This commit is contained in:
Luke Harding 2024-05-02 20:59:35 -04:00
parent 969791f127
commit 2ca439ac6d
4 changed files with 18 additions and 0 deletions

View File

@ -1,3 +1,6 @@
PORT=
BIND_ADDR=
DB_PASSWORD=
DB_USER=
DB_HOST=

7
server/Cargo.lock generated
View File

@ -415,6 +415,12 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "dotenvy"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "encoding_rs"
version = "0.8.34"
@ -741,6 +747,7 @@ version = "0.1.0"
dependencies = [
"actix-web",
"colored",
"dotenvy",
]
[[package]]

View File

@ -7,3 +7,4 @@ license = "GPL-3.0-only"
[dependencies]
actix-web = "4.5.1"
colored = "2.1.0"
dotenvy = "0.15.7"

View File

@ -5,6 +5,8 @@ use std::env;
use actix_web::{App, get, HttpResponse, HttpServer, Responder};
use crate::util::warn_println;
mod util;
#[actix_web::main]
@ -15,6 +17,11 @@ async fn main() -> std::io::Result<()> {
let mut port = 8000;
let mut bind_addr = String::from("127.0.0.1");
// Load .env
if let Err(e) = dotenvy::dotenv() {
warn_println(format!("Failed to load dotenv: {}", e))
};
// 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>() {