fix errors when no config is passed; add health check endpoint; add response caching
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
||||||
namespace Finch;
|
namespace Finch;
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ public static class ApplicationBuilderExtensions
|
|||||||
public static IApplicationBuilder UseFinch(this IApplicationBuilder app)
|
public static IApplicationBuilder UseFinch(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.UseMiddleware<FinchContextMiddleware>();
|
app.UseMiddleware<FinchContextMiddleware>();
|
||||||
|
app.UseResponseCaching();
|
||||||
app.UseOutputCache();
|
app.UseOutputCache();
|
||||||
|
|
||||||
if (app is WebApplication webApplication)
|
if (app is WebApplication webApplication)
|
||||||
@@ -15,7 +17,7 @@ public static class ApplicationBuilderExtensions
|
|||||||
webApplication.MapControllers();
|
webApplication.MapControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
FinchBuilder.Modules.Configure(app, null, app.ApplicationServices);
|
FinchBuilder.Modules.Configure(app, app as IEndpointRouteBuilder, app.ApplicationServices);
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class FinchBuilder
|
|||||||
startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
|
startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
|
||||||
setupAction?.Invoke(startupOptions);
|
setupAction?.Invoke(startupOptions);
|
||||||
|
|
||||||
|
services.AddResponseCaching();
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
services.AddOutputCache();
|
services.AddOutputCache();
|
||||||
mvcBuilder = services.AddRazorPages();
|
mvcBuilder = services.AddRazorPages();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class FinchLoggingModule : FinchModule
|
|||||||
{
|
{
|
||||||
// get seq configuration
|
// get seq configuration
|
||||||
IConfigurationSection seqConfig = configuration.GetSection("Finch:Seq");
|
IConfigurationSection seqConfig = configuration.GetSection("Finch:Seq");
|
||||||
FinchSeqOptions seqOptions = seqConfig.Get<FinchSeqOptions>();
|
FinchSeqOptions seqOptions = seqConfig.Get<FinchSeqOptions>() ?? new();
|
||||||
|
|
||||||
// default level
|
// default level
|
||||||
builder.SetMinimumLevel(seqOptions.MinimumLevel);
|
builder.SetMinimumLevel(seqOptions.MinimumLevel);
|
||||||
@@ -27,7 +27,7 @@ public class FinchLoggingModule : FinchModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add optional seq sink
|
// add optional seq sink
|
||||||
if (seqConfig.Exists())
|
if (seqConfig.Exists() && seqOptions.ApiKey.HasValue())
|
||||||
{
|
{
|
||||||
builder.AddSeq(seqOptions.ServerUrl, seqOptions.ApiKey, seqOptions.Enrichers);
|
builder.AddSeq(seqOptions.ServerUrl, seqOptions.ApiKey, seqOptions.Enrichers);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Finch.Mvc;
|
namespace Finch.Mvc;
|
||||||
@@ -8,5 +10,12 @@ public class FinchMvcModule : FinchModule
|
|||||||
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddRouting(opts => opts.LowercaseUrls = true);
|
services.AddRouting(opts => opts.LowercaseUrls = true);
|
||||||
|
services.AddHealthChecks();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
routes.MapHealthChecks("/health");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user