From be3d2ed4780d612606377c27020b06ccbd5f544c Mon Sep 17 00:00:00 2001 From: kieran Date: Mon, 19 Aug 2024 15:42:03 +0100 Subject: [PATCH] Config listen address --- src/main.rs | 11 ++++++++++- src/settings.rs | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index cab6d20..1ef5660 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate rocket; +use std::net::{IpAddr, SocketAddr}; use std::time::Duration; use anyhow::Error; @@ -44,7 +45,15 @@ async fn main() -> Result<(), Error> { } }); - let rocket = rocket::Rocket::build() + let mut config = rocket::Config::default(); + let ip: SocketAddr = match &settings.listen { + Some(i) => i.parse().unwrap(), + None => SocketAddr::new(IpAddr::from([0, 0, 0, 0]), 8000) + }; + config.address = ip.ip(); + config.port = ip.port(); + + let rocket = rocket::Rocket::custom(config) .manage(db) .manage(fetch) .attach(Shield::new()) // disable diff --git a/src/settings.rs b/src/settings.rs index 4abb15d..b3a8051 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -3,6 +3,9 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Settings { + /// Listen address for web API + pub listen: Option, + /// List of relays to connect to for fetching data pub relays: Vec } \ No newline at end of file