added use infrastructure

master
Young 6 months ago
parent f4b16bd7a3
commit 1c969999ba

@ -1,13 +1,45 @@
using Asp.Versioning.ApiExplorer;
using Infrastructure.Seed;
using Infrastructure.Middlewares;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.HttpOverrides;
using Serilog;
namespace Infrastructure.Extensions;
public static class ApplicationBuilderExtension
{
public static IApplicationBuilder UseDefaultInfrastructure(this WebApplication app)
{
ArgumentNullException.ThrowIfNull(app);
if (app.Environment.IsDevelopment() || app.Environment.IsStaging())
{
app.UseSwagger();
app.UseDefaultSwaggerUI();
app.MapGet("/", request =>
{
request.Response.Redirect("/swagger");
return Task.CompletedTask;
});
}
app.UseDefaultExceptionHandler()
.UseRouting()
.UseCors(Options.CorsOptions.SectionName)
.UseMiddleware<NotFoundMiddleware>()
.UseAuthentication()
.UseAuthorization()
.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.MapControllers();
app.Run();
return app;
}
public static IApplicationBuilder UseDefaultSwaggerUI(this IApplicationBuilder app)
{
ArgumentNullException.ThrowIfNull(app);
@ -29,7 +61,7 @@ public static class ApplicationBuilderExtension
ArgumentNullException.ThrowIfNull(app);
app.UseExceptionHandler(options =>
{
options.Run(async context=>
options.Run(async context =>
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = StatusCodes.Status200OK;

Loading…
Cancel
Save