Skip to content

Commit 3935463

Browse files
graysideknative-prow-robot
authored andcommitted
serving/helloworld-csharp: respect the port env var (#462)
1 parent 224ef9c commit 3935463

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

serving/samples/helloworld-csharp/Program.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ public static void Main(string[] args)
1717
CreateWebHostBuilder(args).Build().Run();
1818
}
1919

20-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21-
WebHost.CreateDefaultBuilder(args)
22-
.UseStartup<Startup>().UseUrls("http://0.0.0.0:8080");
20+
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
21+
{
22+
string port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
23+
string url = String.Concat("http://0.0.0.0:", port);
24+
25+
return WebHost.CreateDefaultBuilder(args)
26+
.UseStartup<Startup>().UseUrls(url);
27+
}
2328
}
2429
}

serving/samples/helloworld-csharp/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ recreate the source files from this folder.
2626
```
2727

2828
1. Update the `CreateWebHostBuilder` definition in `Program.cs` by adding
29-
`.UseUrls("http://0.0.0.0:8080")` to define the serving port:
29+
`.UseUrls()` to define the serving port:
3030
3131
```csharp
32-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
33-
WebHost.CreateDefaultBuilder(args)
34-
.UseStartup<Startup>().UseUrls("http://0.0.0.0:8080");
32+
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
33+
{
34+
string port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
35+
string url = String.Concat("http://0.0.0.0:", port);
36+
37+
return WebHost.CreateDefaultBuilder(args)
38+
.UseStartup<Startup>().UseUrls(url);
39+
}
3540
```
3641

3742
1. Update the `app.Run(...)` statement in `Startup.cs` to read and return the

0 commit comments

Comments
 (0)