Skip to content

Commit dbdf3c9

Browse files
graysideknative-prow-robot
authored andcommitted
serving/helloworld-rust: respect the PORT env var (#464)
1 parent 070c88b commit dbdf3c9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

serving/samples/helloworld-rust/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
A simple web app written in Rust that you can use for testing.
44
It reads in an env variable `TARGET` and prints "Hello ${TARGET}!". If
5+
56
TARGET is not specified, it will use "World" as the TARGET.
67

78
## Prerequisites
@@ -48,7 +49,17 @@ following instructions recreate the source files from this folder.
4849
fn main() {
4950
pretty_env_logger::init();
5051

51-
let addr = ([0, 0, 0, 0], 8080).into();
52+
let mut port: u16 = 8080;
53+
match env::var("PORT") {
54+
Ok(p) => {
55+
match p.parse::<u16>() {
56+
Ok(n) => {port = n;},
57+
Err(_e) => {},
58+
};
59+
}
60+
Err(_e) => {},
61+
};
62+
let addr = ([0, 0, 0, 0], port).into();
5263

5364
let new_service = || {
5465
service_fn_ok(|_| {

serving/samples/helloworld-rust/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ use std::env;
1010
fn main() {
1111
pretty_env_logger::init();
1212

13-
let addr = ([0, 0, 0, 0], 8080).into();
13+
let mut port: u16 = 8080;
14+
match env::var("PORT") {
15+
Ok(p) => {
16+
match p.parse::<u16>() {
17+
Ok(n) => {port = n;},
18+
Err(_e) => {},
19+
};
20+
}
21+
Err(_e) => {},
22+
};
23+
let addr = ([0, 0, 0, 0], port).into();
1424

1525
let new_service = || {
1626
service_fn_ok(|_| {

0 commit comments

Comments
 (0)