Skip to content

Commit

Permalink
Try server feature to get internal details.
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Dec 17, 2024
1 parent f9bba3c commit b0a4fa6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ProfanityFilter.WebApi/Components/Pages/Home.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace ProfanityFilter.WebApi.Components.Pages;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.Logging;

namespace ProfanityFilter.WebApi.Components.Pages;

[StreamRendering]
public sealed partial class Home : IAsyncDisposable
Expand All @@ -25,6 +28,9 @@ public sealed partial class Home : IAsyncDisposable
[Inject]
public required NavigationManager Nav { get; set; }

[Inject]
public required IServerAddressesFeature ServerAddresses { get; set; }

[Inject]
public required ILocalStorageService LocalStorage { get; set; }

Expand Down Expand Up @@ -62,7 +68,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (_hub is null)
{
var uri = new UriBuilder(Nav.BaseUri)
var baseAddress = ServerAddresses.Addresses.FirstOrDefault();

Logger.LogInformation("Attempting hub base address: {Address}", baseAddress);

var uri = new UriBuilder(baseAddress ?? Nav.BaseUri)
{
Path = "/profanity/hub"
};
Expand Down
11 changes: 11 additions & 0 deletions src/ProfanityFilter.WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton<IServerAddressesFeature>(sp =>
{
var server = sp.GetRequiredService<IServer>();

return server.Features.Get<IServerAddressesFeature>()
?? throw new InvalidOperationException("There's no IServerAddressesFeature in the IServer.");
});

builder.Services.AddRedaction(static redaction =>
redaction.SetRedactor<CharacterRedactor>(
classifications: [DataClassifications.SensitiveData]));
Expand Down

0 comments on commit b0a4fa6

Please sign in to comment.