From c10eeafed15c85a3fad7ab39a6e672ead73da601 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 8 Nov 2021 13:00:08 +0000 Subject: [PATCH] Allow configuring the bind address --- src/state.rs | 1 + src/web.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/state.rs b/src/state.rs index 1c00923..dd74d17 100644 --- a/src/state.rs +++ b/src/state.rs @@ -14,6 +14,7 @@ pub struct State { #[derive(Clone, Deserialize)] pub struct Config { + pub bind_address: String, pub matrix_id: String, pub matrix_room: String, pub matrix_store: PathBuf, diff --git a/src/web.rs b/src/web.rs index d7a5990..02d16d2 100644 --- a/src/web.rs +++ b/src/web.rs @@ -8,6 +8,7 @@ use matrix_sdk::ruma::RoomId; use monzo::accounts::Type; use serde::Deserialize; use std::collections::HashMap; +use std::net::SocketAddr; use std::str::FromStr; use url::Url; use warp::http::{Response, StatusCode}; @@ -207,7 +208,10 @@ async fn monzo_hook_wrapped( /// - setting up Monzo access tokens /// - receiving Monzo webhooks pub async fn warp_main(state: State) { - let with_state = warp::any().map(move || state.clone()); + let with_state = { + let state = state.clone(); + warp::any().map(move || state.clone()) + }; let auth_setup_route = warp::get() .and(warp::path("auth_setup")) // .and(warp::header("Host")) @@ -237,5 +241,7 @@ pub async fn warp_main(state: State) { .or(auth_confirmed_route) .or(hook_route); - warp::serve(routes).run(([127, 0, 0, 1], 3030)).await; + let address: SocketAddr = + SocketAddr::from_str(&state.config.bind_address).expect("Failed to parse bind address"); + warp::serve(routes).run(address).await; }