From 1bc845b398715167b0ed5775ce7496317f975c5d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Nov 2024 13:23:16 +0100 Subject: [PATCH] binding depends on compilation --- src/main.rs | 6 +++++- src/utils/misc.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index cf9dab7..900426e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use actix_web::{ web, App, HttpServer, }; use std::io::Result; +use utils::misc::is_debug; use crate::routes::{ agreements, api_v1, blog, contact, contrib, cours, cv, gaming, index, memorial, not_found, @@ -20,7 +21,10 @@ mod utils; async fn main() -> Result<()> { let config = config::get_configuration("./config/config.toml"); - let addr = ("0.0.0.0", config.fc.port.unwrap()); + let addr = ( + if is_debug() { "127.0.0.1" } else { "0.0.0.0" }, + config.fc.port.unwrap(), + ); println!( "Listening to {}://{}:{}", diff --git a/src/utils/misc.rs b/src/utils/misc.rs index 4d7aee5..693940c 100644 --- a/src/utils/misc.rs +++ b/src/utils/misc.rs @@ -87,3 +87,12 @@ fn read_pdf(data: Vec) -> File { ), } } +#[cfg(debug_assertions)] +pub fn is_debug() -> bool { + true +} + +#[cfg(not(debug_assertions))] +pub fn is_debug() -> bool { + false +}