mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(api): cleanup
This commit is contained in:
parent
ed15c2623e
commit
23010fb5ea
3 changed files with 21 additions and 26 deletions
|
|
@ -11,7 +11,8 @@ internal static class CorsConfiguration
|
|||
options.AddDefaultPolicy(policy => policy
|
||||
.SetIsOriginAllowed(origin =>
|
||||
{
|
||||
if (corsOptions.AllowedOrigins.Any(o => string.Equals(o, origin, StringComparison.OrdinalIgnoreCase)))
|
||||
if (corsOptions.AllowedOrigins.Any(o =>
|
||||
string.Equals(o, origin, StringComparison.OrdinalIgnoreCase)))
|
||||
return true;
|
||||
|
||||
if (corsOptions.StagingOriginPatterns is { } patterns &&
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using FilterLists.Directory.Api.Cors;
|
||||
using FilterLists.Directory.Api.OpenApi;
|
||||
using FilterLists.Directory.Application;
|
||||
using FilterLists.ServiceDefaults;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
using Azure.Monitor.OpenTelemetry.AspNetCore;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.ServiceDiscovery;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace Microsoft.Extensions.Hosting;
|
||||
namespace FilterLists.ServiceDefaults;
|
||||
|
||||
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
|
||||
// This project should be referenced by each service project in your solution.
|
||||
|
|
@ -36,15 +38,13 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where
|
|||
});
|
||||
|
||||
// Uncomment the following to restrict the allowed schemes for service discovery.
|
||||
builder.Services.Configure<ServiceDiscoveryOptions>(options =>
|
||||
{
|
||||
options.AllowedSchemes = ["https"];
|
||||
});
|
||||
builder.Services.Configure<ServiceDiscoveryOptions>(options => { options.AllowedSchemes = ["https"]; });
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder)
|
||||
where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
builder.Logging.AddOpenTelemetry(logging =>
|
||||
{
|
||||
|
|
@ -78,35 +78,28 @@ public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) w
|
|||
return builder;
|
||||
}
|
||||
|
||||
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
private static void AddOpenTelemetryExporters<TBuilder>(this TBuilder builder)
|
||||
where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
|
||||
|
||||
if (useOtlpExporter)
|
||||
{
|
||||
builder.Services.AddOpenTelemetry().UseOtlpExporter();
|
||||
}
|
||||
if (useOtlpExporter) builder.Services.AddOpenTelemetry().UseOtlpExporter();
|
||||
|
||||
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
|
||||
if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
|
||||
{
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.UseAzureMonitor();
|
||||
}
|
||||
|
||||
return builder;
|
||||
.UseAzureMonitor();
|
||||
}
|
||||
|
||||
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder)
|
||||
where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
builder.Services.AddRequestTimeouts(
|
||||
configure: static timeouts =>
|
||||
timeouts.AddPolicy("HealthChecks", TimeSpan.FromSeconds(5)));
|
||||
builder.Services.AddRequestTimeouts(static timeouts =>
|
||||
timeouts.AddPolicy("HealthChecks", TimeSpan.FromSeconds(5)));
|
||||
|
||||
builder.Services.AddOutputCache(
|
||||
configureOptions: static caching =>
|
||||
caching.AddPolicy("HealthChecks",
|
||||
build: static policy => policy.Expire(TimeSpan.FromSeconds(10))));
|
||||
builder.Services.AddOutputCache(static caching =>
|
||||
caching.AddPolicy("HealthChecks",
|
||||
static policy => policy.Expire(TimeSpan.FromSeconds(10))));
|
||||
|
||||
builder.Services.AddHealthChecks()
|
||||
// Add a default liveness check to ensure app is responsive
|
||||
|
|
@ -128,7 +121,7 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)
|
|||
healthChecks.MapHealthChecks(HealthEndpointPath);
|
||||
|
||||
// Only health checks tagged with the "live" tag must pass for app to be considered alive
|
||||
healthChecks.MapHealthChecks(AlivenessEndpointPath, new()
|
||||
healthChecks.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions
|
||||
{
|
||||
Predicate = static r => r.Tags.Contains("live")
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue