-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b51302b
commit 7efd423
Showing
4 changed files
with
34 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/ProfanityFilter.WebApi/Services/BaseAddressResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace ProfanityFilter.WebApi.Services; | ||
|
||
public sealed class BaseAddressResolver( | ||
IConfiguration configuration, | ||
IServerAddressesFeature serverAddresses, | ||
NavigationManager navigationManager) | ||
{ | ||
private bool IsRunningInContainer => configuration.GetValue<bool>("DOTNET_RUNNING_IN_CONTAINER"); | ||
|
||
public string GetBaseAddress() | ||
{ | ||
return IsRunningInContainer switch | ||
{ | ||
// When running in a container, use the internal container port. | ||
true => "https://localhost:8081", | ||
|
||
// Otherwise, rely on the server address or the base URI. | ||
_ => serverAddresses.Addresses.FirstOrDefault(address => address.StartsWith("https")) | ||
?? navigationManager.BaseUri | ||
}; | ||
} | ||
} |