From af7486ed7ed2a61c57d9da2075b0b612803fb49b Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Wed, 17 Oct 2018 10:08:55 -0700 Subject: [PATCH] serving/helloworld-rust: respect the PORT env var --- serving/samples/helloworld-rust/README.md | 16 +++++++++++++--- serving/samples/helloworld-rust/src/main.rs | 12 +++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/serving/samples/helloworld-rust/README.md b/serving/samples/helloworld-rust/README.md index bab1acce52d..d9e84315632 100644 --- a/serving/samples/helloworld-rust/README.md +++ b/serving/samples/helloworld-rust/README.md @@ -1,8 +1,8 @@ # Hello World - Rust sample A simple web app written in Rust that you can use for testing. -It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If -TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET. +It reads in an env variable `TARGET` and prints "Hello ${TARGET}". If +TARGET is not specified, it will use "World" as the TARGET. ## Prerequisites @@ -48,7 +48,17 @@ following instructions recreate the source files from this folder. fn main() { pretty_env_logger::init(); - let addr = ([0, 0, 0, 0], 8080).into(); + let mut port: u16 = 8080; + match env::var("PORT") { + Ok(p) => { + match p.parse::() { + Ok(n) => {port = n;}, + Err(_e) => {}, + }; + } + Err(_e) => {}, + }; + let addr = ([0, 0, 0, 0], port).into(); let new_service = || { service_fn_ok(|_| { diff --git a/serving/samples/helloworld-rust/src/main.rs b/serving/samples/helloworld-rust/src/main.rs index 3afe1ef0da9..3574c04b9b2 100644 --- a/serving/samples/helloworld-rust/src/main.rs +++ b/serving/samples/helloworld-rust/src/main.rs @@ -10,7 +10,17 @@ use std::env; fn main() { pretty_env_logger::init(); - let addr = ([0, 0, 0, 0], 8080).into(); + let mut port: u16 = 8080; + match env::var("PORT") { + Ok(p) => { + match p.parse::() { + Ok(n) => {port = n;}, + Err(_e) => {}, + }; + } + Err(_e) => {}, + }; + let addr = ([0, 0, 0, 0], port).into(); let new_service = || { service_fn_ok(|_| {