Skip to content

Commit fe72d13

Browse files
committed
Only change the webhost url if not running in a container
1 parent c664d2f commit fe72d13

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/docs-builder/Http/DocumentationWebHost.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFile
5454
builder.Services.AddHostedService<ReloadGeneratorService>();
5555

5656
//builder.Services.AddSingleton(logger);
57-
builder.WebHost.UseUrls($"http://localhost:{port}");
57+
58+
// See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_running_in_container-and-dotnet_running_in_containers
59+
// This way use the default port when running in a container
60+
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER")) &&
61+
string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINERS")))
62+
builder.WebHost.UseUrls($"http://localhost:{port}");
63+
5864
_webApplication = builder.Build();
5965
SetUpRoutes();
6066
}

0 commit comments

Comments
 (0)