rocket port

This commit is contained in:
Alex Janka 2024-02-25 11:39:24 +11:00
parent 8b738777a8
commit 8b8049df2f
2 changed files with 8 additions and 2 deletions

View file

@ -15,6 +15,8 @@ mod server;
struct Args {
#[clap(long)]
pairing_data: PathBuf,
#[clap(long, default_value_t = 6666)]
port: usize,
}
const SENSORS: [ServiceType; 11] = [
@ -36,7 +38,7 @@ async fn rocket() -> rocket::Rocket<rocket::Build> {
env_logger::init();
let args = Args::parse();
match init(args.pairing_data).await {
Ok(paired) => launch(paired),
Ok(paired) => launch(paired, args.port),
Err(e) => panic!("Error {e:#?}"),
}
}

View file

@ -5,8 +5,12 @@ use tokio::sync::Mutex;
use crate::SENSORS;
pub fn launch(paired: HashMap<String, DeviceConnection>) -> rocket::Rocket<rocket::Build> {
pub fn launch(
paired: HashMap<String, DeviceConnection>,
port: usize,
) -> rocket::Rocket<rocket::Build> {
rocket::build()
.configure(rocket::Config::figment().merge(("port", port)))
.manage(Mutex::new(paired))
.mount("/", routes![metrics])
}