summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-09 21:04:07 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-03-09 21:04:07 +0100
commit309c8bc5308c8f58d67a6cc9b60de377a614f139 (patch)
treeafd8008c851add0a19ad3201d4019b41358da9b3
parent21ec8d86f701f1a261fa2c3892034c7763a950b6 (diff)
feat: add server configuration by .env
-rw-r--r--README.md2
-rw-r--r--src/config.rs7
-rw-r--r--src/main.rs2
3 files changed, 10 insertions, 1 deletions
diff --git a/README.md b/README.md
index 97b7d42..e4b8d22 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,8 @@
<key>.env</key>
```
+SERVER.HOST=<host>
+SERVER.PORT=<port>
PG.USER=<user>
PG.PASSWORD=<psw>
PG.HOST=<host>
diff --git a/src/config.rs b/src/config.rs
index f10fd08..7146a0b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -2,7 +2,14 @@ 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
}