serving/helloworld-rust: respect the PORT env var (#464)

This commit is contained in:
Adam Ross 2018-10-24 12:22:31 -07:00 committed by Knative Prow Robot
parent 070c88b24a
commit dbdf3c922c
2 changed files with 23 additions and 2 deletions

View File

@ -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::<u16>() {
Ok(n) => {port = n;},
Err(_e) => {},
};
}
Err(_e) => {},
};
let addr = ([0, 0, 0, 0], port).into();
let new_service = || {
service_fn_ok(|_| {

View File

@ -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::<u16>() {
Ok(n) => {port = n;},
Err(_e) => {},
};
}
Err(_e) => {},
};
let addr = ([0, 0, 0, 0], port).into();
let new_service = || {
service_fn_ok(|_| {