Config listen address

This commit is contained in:
kieran 2024-08-19 15:42:03 +01:00
parent add69fecfa
commit be3d2ed478
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use std::net::{IpAddr, SocketAddr};
use std::time::Duration; use std::time::Duration;
use anyhow::Error; 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(db)
.manage(fetch) .manage(fetch)
.attach(Shield::new()) // disable .attach(Shield::new()) // disable

View File

@ -3,6 +3,9 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Settings { pub struct Settings {
/// Listen address for web API
pub listen: Option<String>,
/// List of relays to connect to for fetching data /// List of relays to connect to for fetching data
pub relays: Vec<Url> pub relays: Vec<Url>
} }