aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2022-05-08 16:29:42 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2022-05-08 16:29:42 +0200
commit0df0a957346e03ff98b65cf797b049b874a3161f (patch)
tree4236bb75790d8db169bd2a3e2e5a551449d7c97b /src
parent0964b7fee95d478ecd2b401d8c957b4936902e99 (diff)
downloadmacroblog.rs-0df0a957346e03ff98b65cf797b049b874a3161f.tar.gz
macroblog.rs-0df0a957346e03ff98b65cf797b049b874a3161f.tar.bz2
macroblog.rs-0df0a957346e03ff98b65cf797b049b874a3161f.zip
feat: Add port env var
Now the port can be set through `PORT` enviroment variable, this is useful for deploying on heroku.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 92f51a7..49815b8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,5 @@
use std::convert::Infallible;
-use std::{include_str};
+use std::{include_str, env};
use std::net::SocketAddr;
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
@@ -93,7 +93,8 @@ async fn request(req: Request<Body>) -> Result<Response<Body>, Infallible> {
#[tokio::main]
async fn main() {
- let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
+ let port = env::var("PORT").unwrap_or("3000".into()).parse::<u16>().unwrap_or(300);
+ let addr = SocketAddr::from(([127, 0, 0, 1], port));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(request))