Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0-preview2] Show proxy URL for all executables #1344

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/Resources.razor
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<SourceColumnDisplay Resource="context" FilterText="@_filter" />
</TemplateColumn>
<TemplateColumn Title="Endpoints">
<EndpointsColumnDisplay Resource="context" />
<EndpointsColumnDisplay Resource="context" HasMultipleReplicas="HasMultipleReplicas(context)" />
</TemplateColumn>
<TemplateColumn Title="Environment" Sortable="false">
<FluentButton Appearance="Appearance.Lightweight"
Expand Down
18 changes: 18 additions & 0 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ private async Task OnResourceListChanged(ObjectChangeType objectChangeType, Reso

private string GetResourceName(ResourceViewModel resource) => ResourceViewModel.GetResourceName(resource, _resourcesMap.Values);

private bool HasMultipleReplicas(ResourceViewModel resource)
{
var count = 0;
foreach (var item in _resourcesMap.Values)
{
if (item.DisplayName == resource.DisplayName)
{
count++;
if (count >= 2)
{
return true;
}
}
}

return false;
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
@* If we have any, regardless of the state, go ahead and display them *@
foreach (var endpoint in Resource.Endpoints.OrderBy(e => e))
{
<a href="@endpoint" target="_blank" class="long-inner-content">@endpoint</a>
if (HasMultipleReplicas)
{
<a href="@endpoint.ProxyUrl" target="_blank" class="long-inner-content">@endpoint.ProxyUrl</a>
<span class="long-inner-content">(<a href="@endpoint.EndpointUrl" target="_blank">@endpoint.EndpointUrl</a>)</span>
}
else
{
<a href="@endpoint.ProxyUrl" target="_blank" class="long-inner-content">@endpoint.ProxyUrl</a>
}
}
@* If we're expecting more, say Starting..., unless the app isn't running anymore *@
if (Resource.State != FinishedState
Expand All @@ -30,4 +38,7 @@

[Parameter, EditorRequired]
public required ResourceViewModel Resource { get; set; }

[Parameter, EditorRequired]
public required bool HasMultipleReplicas { get; set; }
}
4 changes: 3 additions & 1 deletion src/Aspire.Dashboard/Model/ResourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class ResourceViewModel
public DateTime? CreationTimeStamp { get; init; }
public List<EnvironmentVariableViewModel> Environment { get; } = new();
public required ILogSource LogSource { get; init; }
public List<string> Endpoints { get; } = new();
public List<EndpointViewModel> Endpoints { get; } = new();
public List<ResourceService> Services { get; } = new();
public int? ExpectedEndpointsCount { get; init; }
public abstract string ResourceType { get; }
Expand Down Expand Up @@ -46,3 +46,5 @@ public sealed class ResourceService(string name, string? allocatedAddress, int?
}

public sealed record NamespacedName(string Name, string? Namespace);

public sealed record EndpointViewModel(string EndpointUrl, string ProxyUrl);
5 changes: 4 additions & 1 deletion src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ private void FillEndpoints(
if (matchingService?.UsesHttpProtocol(out var uriScheme) == true)
{
var endpointString = $"{uriScheme}://{endpoint.Spec.Address}:{endpoint.Spec.Port}";
var proxyUrlString = $"{uriScheme}://{matchingService.AllocatedAddress}:{matchingService.AllocatedPort}";

// For project look into launch profile to append launch url
if (resourceViewModel is ProjectViewModel projectViewModel
Expand All @@ -416,6 +417,7 @@ private void FillEndpoints(
{
// This is relative URL
endpointString += $"/{launchUrl}";
proxyUrlString += $"/{launchUrl}";
}
else
{
Expand All @@ -424,13 +426,14 @@ private void FillEndpoints(
&& launchUrl.StartsWith(applicationUrl))
{
endpointString = launchUrl.Replace(applicationUrl, endpointString);
proxyUrlString = launchUrl;
}
}

// If we cannot process launchUrl then we just show endpoint string
}

resourceViewModel.Endpoints.Add(endpointString);
resourceViewModel.Endpoints.Add(new(endpointString, proxyUrlString));
}
}

Expand Down