config: separate option for port setting

This commit is contained in:
MedzikUser 2022-04-19 15:25:56 +02:00
parent ac2eff6399
commit b5ee35dfe8
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
3 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,6 @@
[http] [http]
host = "0.0.0.0:8080" host = "0.0.0.0"
port = 8080
cors = [ cors = [
"127.0.0.1:8000", "127.0.0.1:8000",
"localhost:8000", "localhost:8000",

View File

@ -20,7 +20,13 @@ async fn main() {
.map(|e| e.parse().expect("parse CORS host")) .map(|e| e.parse().expect("parse CORS host"))
.collect(); .collect();
homedisk_server::serve(config.http.host.clone(), origins, db, config) let host = format!(
"{host}:{port}",
host = config.http.host,
port = config.http.port
);
homedisk_server::serve(host, origins, db, config)
.await .await
.expect("start http server"); .expect("start http server");
} }

View File

@ -13,6 +13,7 @@ pub struct Config {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigHTTP { pub struct ConfigHTTP {
pub host: String, pub host: String,
pub port: u16,
pub cors: Vec<String>, pub cors: Vec<String>,
} }