Allow configuring the bind address

This commit is contained in:
Olivier 'reivilibre' 2021-11-08 13:00:08 +00:00
parent 1095ef0aa6
commit c10eeafed1
2 changed files with 9 additions and 2 deletions

View File

@ -14,6 +14,7 @@ pub struct State {
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize)]
pub struct Config { pub struct Config {
pub bind_address: String,
pub matrix_id: String, pub matrix_id: String,
pub matrix_room: String, pub matrix_room: String,
pub matrix_store: PathBuf, pub matrix_store: PathBuf,

View File

@ -8,6 +8,7 @@ use matrix_sdk::ruma::RoomId;
use monzo::accounts::Type; use monzo::accounts::Type;
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::net::SocketAddr;
use std::str::FromStr; use std::str::FromStr;
use url::Url; use url::Url;
use warp::http::{Response, StatusCode}; use warp::http::{Response, StatusCode};
@ -207,7 +208,10 @@ async fn monzo_hook_wrapped(
/// - setting up Monzo access tokens /// - setting up Monzo access tokens
/// - receiving Monzo webhooks /// - receiving Monzo webhooks
pub async fn warp_main(state: State) { 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() let auth_setup_route = warp::get()
.and(warp::path("auth_setup")) .and(warp::path("auth_setup"))
// .and(warp::header("Host")) // .and(warp::header("Host"))
@ -237,5 +241,7 @@ pub async fn warp_main(state: State) {
.or(auth_confirmed_route) .or(auth_confirmed_route)
.or(hook_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;
} }