Skip to content

Commit

Permalink
[NO-ISSUE] fix: allow to bind other host with env var (#38)
Browse files Browse the repository at this point in the history
* fix: allow to bind other host with env var

* fix: use app name in env vars
  • Loading branch information
GuillaumeDecMeetsMore authored Aug 30, 2024
1 parent 06203b8 commit 1d61bd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions scheduler/crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use nettu_scheduler_domain::{
ID,
};
use nettu_scheduler_infra::NettuContext;
use tracing::warn;
use tracing::{info, warn};
use tracing_actix_web::TracingLogger;

pub fn configure_server_api(cfg: &mut web::ServiceConfig) {
Expand Down Expand Up @@ -82,8 +82,10 @@ impl Application {

async fn configure_server(context: NettuContext) -> Result<(Server, u16), std::io::Error> {
let port = context.config.port;
let address = format!("127.0.0.1:{}", port);
let listener = TcpListener::bind(address)?;
let address = std::env::var("NITTEI_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
let address_and_port = format!("{}:{}", address, port);
info!("Starting server on: {}", address_and_port);
let listener = TcpListener::bind(address_and_port)?;
let port = listener.local_addr().unwrap().port();

let server = HttpServer::new(move || {
Expand Down
2 changes: 1 addition & 1 deletion scheduler/crates/infra/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Config {
}
};
let default_port = "5000";
let port = std::env::var("PORT").unwrap_or_else(|_| default_port.into());
let port = std::env::var("NITTEI_PORT").unwrap_or_else(|_| default_port.into());
let port = match port.parse::<usize>() {
Ok(port) => port,
Err(_) => {
Expand Down

0 comments on commit 1d61bd0

Please sign in to comment.