Skip to content

Commit 471ba5e

Browse files
committed
main: start and bind webserver according to webserver option
1 parent 4b6c8be commit 471ba5e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/main.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,27 @@ async fn tokio_main(
165165
let accessory_started = Arc::new(Notify::new());
166166
let accessory_started_cloned = accessory_started.clone();
167167

168-
// preparing AppState and starting webserver
169-
let state = web::AppState {
170-
config: Arc::new(Mutex::new(config.clone())),
171-
config_file: config_file.into(),
172-
};
173-
let app = web::app(state.into());
174-
175-
let addr = SocketAddr::from(([0, 0, 0, 0], 80));
176-
info!("Server running at http://{addr}/");
177-
hyper::Server::bind(&addr)
178-
.serve(app.into_make_service())
179-
.await
180-
.unwrap();
168+
if let Some(ref bindaddr) = config.webserver {
169+
// preparing AppState and starting webserver
170+
let state = web::AppState {
171+
config: Arc::new(Mutex::new(config.clone())),
172+
config_file: config_file.into(),
173+
};
174+
let app = web::app(state.into());
175+
176+
match bindaddr.parse::<SocketAddr>() {
177+
Ok(addr) => {
178+
info!("{} webserver running at http://{addr}/", NAME);
179+
hyper::Server::bind(&addr)
180+
.serve(app.into_make_service())
181+
.await
182+
.unwrap();
183+
}
184+
Err(e) => {
185+
error!("{} webserver address/port parse: {}", NAME, e);
186+
}
187+
}
188+
}
181189

182190
let wifi_conf = {
183191
if !config.wired.is_some() {

0 commit comments

Comments
 (0)