From b9853be186eb62cbe76341175e7ba62f3f05625c Mon Sep 17 00:00:00 2001 From: Chevdor Date: Tue, 31 Mar 2020 15:53:16 +0200 Subject: [PATCH] Listen by default to the local interface and allows changing it (#246) --- README.md | 13 +++++++++++++ backend/src/main.rs | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 018e701..9d87bdd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,19 @@ cd backend cargo build --release ./target/release/telemetry ``` + +By default, telemetry will listen on the local interface only (127.0.0.1) on port 8000. You may change both those values: + +Use another port: +``` +PORT=8123 telemetry +``` + +You may also change the the listening interface. This is especially required if you are using docker: +``` +BIND=0.0.0.0 telemetry +``` + ### Terminal 2 - Frontend ``` yarn start:frontend diff --git a/backend/src/main.rs b/backend/src/main.rs index e35b411..66ba649 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -90,6 +90,8 @@ fn health( }) } +/// Telemetry entry point. Listening by default on 127.0.0.1:8000. +/// This can be changed using the `PORT` and `BIND` ENV variables. fn main() -> std::io::Result<()> { use web::{resource, get}; @@ -101,6 +103,7 @@ fn main() -> std::io::Result<()> { let locator = SyncArbiter::start(4, move || factory.create()); let port = std::env::var("PORT").ok().and_then(|v| v.parse().ok()).unwrap_or(8000u16); + let bind_address = std::env::var("BIND").ok().unwrap_or("127.0.0.1".to_string()); HttpServer::new(move || { App::new() @@ -115,7 +118,7 @@ fn main() -> std::io::Result<()> { .service(resource("/health").route(get().to_async(health))) .service(resource("/health/").route(get().to_async(health))) }) - .bind(format!("0.0.0.0:{}", port))? + .bind(format!("{}:{}", bind_address, port))? .start(); sys.run()