Skip to content

Commit f2c016d

Browse files
Add WithHttpHealthCheck/WithHttpsHealthCheck. (#6081)
* Add WithHttpHealthCheck/WithHttpsHealthCheck. * Update src/Aspire.Hosting/ResourceBuilderExtensions.cs Co-authored-by: David Fowler <davidfowl@gmail.com> * Update src/Aspire.Hosting/ResourceBuilderExtensions.cs * Update playground with another project so I can interactively test things out. * Fix up tests. * Centralize checks/exceptions. * Add requires docker attributes. --------- Co-authored-by: David Fowler <davidfowl@gmail.com>
1 parent 820b33c commit f2c016d

File tree

22 files changed

+497
-4
lines changed

22 files changed

+497
-4
lines changed

Aspire.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureContainerApps.AppHost"
634634
EndProject
635635
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureContainerApps.ApiService", "playground\AzureContainerApps\AzureContainerApps.ApiService\AzureContainerApps.ApiService.csproj", "{683D8264-2755-4455-A6D4-14F7A6AC7B54}"
636636
EndProject
637+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaitFor.Frontend", "playground\waitfor\WaitFor.Frontend\WaitFor.Frontend.csproj", "{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}"
638+
EndProject
637639
Global
638640
GlobalSection(SolutionConfigurationPlatforms) = preSolution
639641
Debug|Any CPU = Debug|Any CPU
@@ -1668,6 +1670,10 @@ Global
16681670
{683D8264-2755-4455-A6D4-14F7A6AC7B54}.Debug|Any CPU.Build.0 = Debug|Any CPU
16691671
{683D8264-2755-4455-A6D4-14F7A6AC7B54}.Release|Any CPU.ActiveCfg = Release|Any CPU
16701672
{683D8264-2755-4455-A6D4-14F7A6AC7B54}.Release|Any CPU.Build.0 = Release|Any CPU
1673+
{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1674+
{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
1675+
{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
1676+
{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}.Release|Any CPU.Build.0 = Release|Any CPU
16711677
EndGlobalSection
16721678
GlobalSection(SolutionProperties) = preSolution
16731679
HideSolutionNode = FALSE
@@ -1973,6 +1979,7 @@ Global
19731979
{D47C77F3-49F4-4741-9786-6F68FC50587E} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
19741980
{96A5B854-2C72-49C8-A91B-2643B814DB2A} = {D47C77F3-49F4-4741-9786-6F68FC50587E}
19751981
{683D8264-2755-4455-A6D4-14F7A6AC7B54} = {D47C77F3-49F4-4741-9786-6F68FC50587E}
1982+
{C88BBF0B-7566-48BD-A2BC-05374B1A2B22} = {3FF3F00C-95C0-46FC-B2BE-A3920C71E393}
19761983
EndGlobalSection
19771984
GlobalSection(ExtensibilityGlobals) = postSolution
19781985
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<PackageVersion Include="AspNetCore.HealthChecks.Rabbitmq" Version="8.0.2" />
8686
<PackageVersion Include="AspNetCore.HealthChecks.Redis" Version="8.0.1" />
8787
<PackageVersion Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
88+
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" />
8889
<!-- efcore dependencies -->
8990
<PackageVersion Include="Microsoft.EntityFrameworkCore.Cosmos" Version="$(MicrosoftEntityFrameworkCoreCosmosPackageVersion)" />
9091
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(MicrosoftEntityFrameworkCoreSqlServerPackageVersion)" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="app.css" />
9+
<link rel="stylesheet" href="WaitFor.Frontend.styles.css" />
10+
<HeadOutlet />
11+
</head>
12+
13+
<body>
14+
<Routes />
15+
<script src="_framework/blazor.web.js"></script>
16+
</body>
17+
18+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@inherits LayoutComponentBase
2+
3+
@Body
4+
5+
<div id="blazor-error-ui">
6+
An unhandled error has occurred.
7+
<a href="" class="reload">Reload</a>
8+
<a class="dismiss">🗙</a>
9+
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#blazor-error-ui {
2+
background: lightyellow;
3+
bottom: 0;
4+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
5+
display: none;
6+
left: 0;
7+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
8+
position: fixed;
9+
width: 100%;
10+
z-index: 1000;
11+
}
12+
13+
#blazor-error-ui .dismiss {
14+
cursor: pointer;
15+
position: absolute;
16+
right: 0.75rem;
17+
top: 0.5rem;
18+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@page "/Error"
2+
@using System.Diagnostics
3+
4+
<PageTitle>Error</PageTitle>
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>
26+
27+
@code{
28+
[CascadingParameter]
29+
private HttpContext? HttpContext { get; set; }
30+
31+
private string? RequestId { get; set; }
32+
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
33+
34+
protected override void OnInitialized() =>
35+
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
36+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/"
2+
@inject ApiClient client
3+
@rendermode InteractiveServer
4+
5+
<PageTitle>Home</PageTitle>
6+
7+
<button @onclick="SendRequest">Fetch data</button>
8+
<textarea>@getResponse</textarea>
9+
10+
@code
11+
{
12+
private string? getResponse = "";
13+
14+
private async Task SendRequest()
15+
{
16+
getResponse = await client.GetDataAsync();
17+
}
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
4+
<FocusOnNavigate RouteData="routeData" Selector="h1" />
5+
</Found>
6+
</Router>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
7+
@using Microsoft.AspNetCore.Components.Web.Virtualization
8+
@using Microsoft.JSInterop
9+
@using WaitFor.Frontend
10+
@using WaitFor.Frontend.Components
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using WaitFor.Frontend.Components;
5+
6+
var builder = WebApplication.CreateBuilder(args);
7+
8+
builder.AddServiceDefaults();
9+
builder.Services.AddHttpClient<ApiClient>(c => c.BaseAddress = new("http://api"));
10+
11+
// Add services to the container.
12+
builder.Services.AddRazorComponents()
13+
.AddInteractiveServerComponents();
14+
15+
var app = builder.Build();
16+
17+
// Configure the HTTP request pipeline.
18+
if (!app.Environment.IsDevelopment())
19+
{
20+
app.UseExceptionHandler("/Error", createScopeForErrors: true);
21+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
22+
app.UseHsts();
23+
}
24+
25+
app.UseHttpsRedirection();
26+
27+
app.UseStaticFiles();
28+
app.UseAntiforgery();
29+
30+
app.MapRazorComponents<App>()
31+
.AddInteractiveServerRenderMode();
32+
33+
app.Run();
34+
35+
public class ApiClient(HttpClient client)
36+
{
37+
public async Task<string> GetDataAsync(CancellationToken cancellationToken = default)
38+
{
39+
return await client.GetStringAsync("/", cancellationToken);
40+
}
41+
}

0 commit comments

Comments
 (0)