Skip to content

Commit

Permalink
UsePathBase instead of adding the base address to each route registra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
C0nquistadore committed Oct 4, 2024
1 parent 55803ca commit 78809c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Dibix.Http.Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ void ConfigureLogging(ILoggingBuilder logging)

WebApplication app = builder.Build();

ILogger logger = loggerFactory.CreateLogger($"Dibix.Http.Host.{nameof(Program)}");
logger.LogInformation("Using path base: {pathBase}", !String.IsNullOrEmpty(hostingOptions.BaseAddress) ? hostingOptions.BaseAddress : "/");

if (!String.IsNullOrWhiteSpace(hostingOptions.BaseAddress))
{
app.UsePathBase(hostingOptions.BaseAddress);
}
app.UseMiddleware<DiagnosticsMiddleware>();
app.UseExceptionHandler();
app.UseRouting();
Expand Down
6 changes: 1 addition & 5 deletions src/Dibix.Http.Host/Registration/DefaultEndpointRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public void Register(IEndpointRouteBuilder builder)
{
foreach (EndpointDefinition endpoint in _endpointMetadataProvider.GetEndpoints())
{
string baseAddress = "";
if (!String.IsNullOrEmpty(_hostingOptions.Value.BaseAddress))
baseAddress = $"/{_hostingOptions.Value.BaseAddress.Trim('/')}";

string route = $"{baseAddress}{endpoint.Url}";
string route = $"{endpoint.Url}";
_logger.LogDebug("Registering route: {method} {route}", endpoint.Method, route);

IEndpointConventionBuilder endpointBuilder = builder.MapMethods(route, EnumerableExtensions.Create(endpoint.Method), _endpointImplementationProvider.GetImplementation(endpoint));
Expand Down

0 comments on commit 78809c0

Please sign in to comment.