Add env variable to define beacon server address
This commit replaces the default hardcoded value for the beacon server address with an envvar. This allows one to run comet on one machine while running the UI on another one (e.g. embedded system).
This commit is contained in:
parent
625fc76f19
commit
d58e9ef191
2 changed files with 18 additions and 5 deletions
|
|
@ -15,8 +15,6 @@ use std::sync::Arc;
|
|||
use std::sync::atomic::{self, AtomicBool};
|
||||
use std::thread;
|
||||
|
||||
pub const SERVER_ADDRESS: &str = "127.0.0.1:9167";
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Client {
|
||||
sender: mpsc::Sender<Action>,
|
||||
|
|
@ -222,9 +220,22 @@ async fn run(
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the address of the beacon server in this environment.
|
||||
///
|
||||
/// The value of the `ICED_BEACON_SERVER_ADDRESS` env variable will
|
||||
/// be returned, if defined.
|
||||
///
|
||||
/// Otherwise, a default local server address will be returned.
|
||||
pub fn server_address_from_env() -> String {
|
||||
const DEFAULT_ADDRESS: &str = "127.0.0.1:9167";
|
||||
|
||||
std::env::var("ICED_BEACON_SERVER_ADDRESS")
|
||||
.unwrap_or_else(|_| String::from(DEFAULT_ADDRESS))
|
||||
}
|
||||
|
||||
async fn _connect() -> Result<net::TcpStream, io::Error> {
|
||||
log::debug!("Attempting to connect to server...");
|
||||
let stream = net::TcpStream::connect(SERVER_ADDRESS).await?;
|
||||
let stream = net::TcpStream::connect(server_address_from_env()).await?;
|
||||
|
||||
stream.set_nodelay(true)?;
|
||||
stream.writable().await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue