diff --git a/serving/samples/helloworld-rust/README.md b/serving/samples/helloworld-rust/README.md index aad4ac2201c..60cfe1e2235 100644 --- a/serving/samples/helloworld-rust/README.md +++ b/serving/samples/helloworld-rust/README.md @@ -2,6 +2,7 @@ A simple web app written in Rust that you can use for testing. 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 +49,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(|_| {