|
|
@ -1,13 +1,45 @@
|
|
|
|
using Asp.Versioning.ApiExplorer;
|
|
|
|
using Asp.Versioning.ApiExplorer;
|
|
|
|
using Infrastructure.Seed;
|
|
|
|
using Infrastructure.Middlewares;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
using Serilog;
|
|
|
|
using Serilog;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure.Extensions;
|
|
|
|
namespace Infrastructure.Extensions;
|
|
|
|
|
|
|
|
|
|
|
|
public static class ApplicationBuilderExtension
|
|
|
|
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)
|
|
|
|
public static IApplicationBuilder UseDefaultSwaggerUI(this IApplicationBuilder app)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ArgumentNullException.ThrowIfNull(app);
|
|
|
|
ArgumentNullException.ThrowIfNull(app);
|
|
|
@ -29,7 +61,7 @@ public static class ApplicationBuilderExtension
|
|
|
|
ArgumentNullException.ThrowIfNull(app);
|
|
|
|
ArgumentNullException.ThrowIfNull(app);
|
|
|
|
app.UseExceptionHandler(options =>
|
|
|
|
app.UseExceptionHandler(options =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
options.Run(async context=>
|
|
|
|
options.Run(async context =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
context.Response.ContentType = "application/json";
|
|
|
|
context.Response.ContentType = "application/json";
|
|
|
|
context.Response.StatusCode = StatusCodes.Status200OK;
|
|
|
|
context.Response.StatusCode = StatusCodes.Status200OK;
|
|
|
|