Skip to content

Commit

Permalink
Add basic healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
steinho committed Mar 25, 2024
1 parent 81933c1 commit 80f30a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Nbic.References/Nbic.References.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -18,6 +18,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
Expand Down
12 changes: 8 additions & 4 deletions Nbic.References/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ReSharper disable once StyleCop.SA1634
// ReSharper disable StyleCop.SA1600

using Microsoft.ApplicationInsights;
using Nbic.References.Infrastructure.Repositories;
using Nbic.References.Infrastructure.Repositories.DbContext;
using Nbic.References.Infrastructure.Services.Indexing;
Expand Down Expand Up @@ -92,7 +91,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<

app.UseAuthentication();
app.UseAuthorization();

app.UseHealthChecks("/hc");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
Expand Down Expand Up @@ -137,7 +136,12 @@ public void ConfigureServices(IServiceCollection services)
.WithExposedHeaders("WWW-Authenticate");
});
});


// health monitoring
services.AddHealthChecks()
.AddDbContextCheck<ReferencesDbContext>();

// no search engine indexing
services.AddStaticRobotsTxt(builder => builder.DenyAll());
}

Expand Down Expand Up @@ -330,7 +334,7 @@ private void AddSwaggerMiddleware(IApplicationBuilder app)
// c.OAuthAdditionalQueryStringParams(new { foo = "bar" });
c.OAuthUseBasicAuthenticationWithAccessCodeGrant();
c.RoutePrefix = string.Empty;
c.DocumentTitle = "Nbic Reference API - swagger documentation";
c.DocumentTitle = "Nbic Reference API - swagger documentation"; // Since swagger doc i index.html - modify title
});
}
}

0 comments on commit 80f30a2

Please sign in to comment.