Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-ISSUE] fix: allow to bind other host with env var #38

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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