Pārlūkot izejas kodu

API addr and port fix

Yurii Sokolovskyi 3 mēneši atpakaļ
vecāks
revīzija
5e8037e3af
2 mainītis faili ar 7 papildinājumiem un 3 dzēšanām
  1. 2 2
      src/config.rs
  2. 5 1
      src/server.rs

+ 2 - 2
src/config.rs

@@ -36,7 +36,7 @@ pub struct Config {
     pub username: String,
     pub password: String,
     pub api_addr: String,
-    pub api_port: String, // TODO make int instead of string?
+    pub api_port: u32,
     pub smtp_domain: String,
     pub smtp_port: u32,
     pub sonic_search_addr: String,
@@ -58,7 +58,7 @@ impl Config {
             "password" => self.password = value.to_string(),
             "maildir" => self.maildir = PathBuf::from(value),
             "api_addr" => self.api_addr = value.to_string(),
-            "api_port" => self.api_port = value.to_string(),
+            "api_port" => self.api_port = value.parse().unwrap(),
             "smtp_domain" => self.smtp_domain = value.to_string(),
             "smtp_port" => self.smtp_port = value.parse().unwrap(),
             "sonic_search_addr" => self.sonic_search_addr = value.to_string(),

+ 5 - 1
src/server.rs

@@ -3,6 +3,8 @@ use crate::indexes::{SerializableMessage, SerializableThread};
 use serde::{Deserialize, Serialize};
 use std::fs::File;
 use std::io::{BufReader};
+use std::net::{IpAddr, SocketAddr};
+use std::str::FromStr;
 use warp::Filter;
 use warp::http::StatusCode;
 use crate::{create_folder_lar, delete_folder_lar, rename_folder_lar};
@@ -48,7 +50,9 @@ pub async fn run_api() {
             .and_then(delete_folder_handle))
         .with(cors);
 
-    warp::serve(routes).run(([127, 0, 0, 1], 3030)).await; // TODO from config
+    let ip: IpAddr = IpAddr::from_str(&*Config::global().api_addr.clone()).expect("Invalid API IP address");
+    let addr = SocketAddr::new(ip, Config::global().api_port.clone() as u16);
+    warp::serve(routes).run(addr).await;
 }
 
 pub async fn get_folders() -> String {