From 309c8bc5308c8f58d67a6cc9b60de377a614f139 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 9 Mar 2021 21:04:07 +0100 Subject: feat: add server configuration by .env --- README.md | 2 ++ src/config.rs | 7 +++++++ src/main.rs | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97b7d42..e4b8d22 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ .env ``` +SERVER.HOST= +SERVER.PORT= PG.USER= PG.PASSWORD= PG.HOST= diff --git a/src/config.rs b/src/config.rs index f10fd08..7146a0b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,15 @@ pub use config::ConfigError; use serde::Deserialize; +#[derive(Deserialize)] +pub struct ServerConfig { + pub host: String, + pub port: u16, +} + #[derive(Deserialize)] pub struct Config { + pub server: ServerConfig, pub pg: deadpool_postgres::Config, } diff --git a/src/main.rs b/src/main.rs index 0ef80bb..51c2f6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ async fn main() -> std::io::Result<()> { .to(|| HttpResponse::Ok().body("Hello from Rust!")), ) }) - .bind("127.0.0.1:8080")? + .bind(format!("{}:{}", config.server.host, config.server.port))? .run() .await } -- cgit v1.2.3-18-g5258