From 647bd917d2ac4d818fe306972880a0c27bad9723 Mon Sep 17 00:00:00 2001 From: Mete Atamel Date: Mon, 4 Mar 2019 17:13:22 +0000 Subject: [PATCH] Further simplified the sample --- serving/samples/helloworld-csharp/Dockerfile | 3 +++ serving/samples/helloworld-csharp/Program.cs | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/serving/samples/helloworld-csharp/Dockerfile b/serving/samples/helloworld-csharp/Dockerfile index 193b55c1e..71f96c58c 100644 --- a/serving/samples/helloworld-csharp/Dockerfile +++ b/serving/samples/helloworld-csharp/Dockerfile @@ -18,5 +18,8 @@ RUN dotnet publish -c Release -o out # This default value facilitates local development. ENV PORT 8080 +# Make sure the app binds to $PORT +ENV ASPNETCORE_URLS http://*:${PORT} + # Run the web service on container startup. CMD ["dotnet", "out/helloworld-csharp.dll"] diff --git a/serving/samples/helloworld-csharp/Program.cs b/serving/samples/helloworld-csharp/Program.cs index a5b02b675..d085bbc20 100644 --- a/serving/samples/helloworld-csharp/Program.cs +++ b/serving/samples/helloworld-csharp/Program.cs @@ -11,13 +11,8 @@ namespace helloworld_csharp CreateWebHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) - { - string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; - string url = String.Concat("http://0.0.0.0:", port); - - return WebHost.CreateDefaultBuilder(args) - .UseStartup().UseUrls(url); - } + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); } }