Fix some issues in the endpoints and use local mongodb
This commit is contained in:
		| @@ -1,90 +1,80 @@ | ||||
| using Core.Blueprint.DAL.Mongo.Configuration; | ||||
| using Core.Blueprint.Logging.Configuration; | ||||
| using Core.Thalos.Adapters.Extensions; | ||||
| using Core.Thalos.Adapters.Helpers; | ||||
| using Core.Thalos.DAL.API.Extensions; | ||||
| using Core.Thalos.Provider; | ||||
| using Microsoft.AspNetCore.RateLimiting; | ||||
| using Microsoft.AspNetCore.ResponseCompression; | ||||
| using System.IO.Compression; | ||||
| using Microsoft.AspNetCore.HttpLogging; | ||||
| using System.Reflection; | ||||
| using System.Threading.RateLimiting; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
|  | ||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "thalos_dal"); | ||||
|  | ||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); | ||||
|  | ||||
| builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly()).AddEnvironmentVariables(); | ||||
|  | ||||
| // Add services to the container. | ||||
|  | ||||
| builder.Services.AddControllers(); | ||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen(); | ||||
| builder.Configuration | ||||
|     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||
|     .AddEnvironmentVariables(); | ||||
|  | ||||
| builder.Services.AddLogs(builder); | ||||
|  | ||||
| builder.Services.AddCors(options => | ||||
| { | ||||
|     options.AddPolicy("AllowAll", policyBuilder => | ||||
|         policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); | ||||
| }); | ||||
| builder.Services.AddMvc().AddJsonOptions(options => | ||||
| { | ||||
|     options.JsonSerializerOptions.WriteIndented = true; | ||||
|     options.JsonSerializerOptions.MaxDepth = 20; | ||||
|     options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; | ||||
| }); | ||||
| builder.Services.Configure<BrotliCompressionProviderOptions>(options => | ||||
| { | ||||
|     options.Level = CompressionLevel.Fastest; | ||||
| }); | ||||
| builder.Services.Configure<GzipCompressionProviderOptions>(options => | ||||
| { | ||||
|     options.Level = CompressionLevel.SmallestSize; | ||||
| }); | ||||
| builder.Services.AddResponseCompression(options => | ||||
| { | ||||
|     options.EnableForHttps = true; | ||||
|     options.Providers.Add<BrotliCompressionProvider>(); | ||||
|     options.Providers.Add<GzipCompressionProvider>(); | ||||
| }); | ||||
|  | ||||
| builder.Services.AddRateLimiter(_ => _ | ||||
|     .AddFixedWindowLimiter("fixed", options => | ||||
|     { | ||||
|         options.PermitLimit = 5; | ||||
|         options.Window = TimeSpan.FromSeconds(10); | ||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; | ||||
|         options.QueueLimit = 2; | ||||
|     }) | ||||
|     .AddSlidingWindowLimiter("sliding", options => | ||||
|     { | ||||
|         options.PermitLimit = 5; | ||||
|         options.Window = TimeSpan.FromSeconds(10); | ||||
|         options.SegmentsPerWindow = 5; | ||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; | ||||
|         options.QueueLimit = 2; | ||||
|     })); | ||||
|  | ||||
| builder.Services.AddResponseCaching(); | ||||
| builder.Services.AddControllers(); | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwagger(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings); | ||||
| builder.Services.AddVersioning(builder.Configuration); | ||||
| builder.Services.AddLogging(); | ||||
| builder.Services.AddResponseCompression(); | ||||
| builder.Services.AddProblemDetails(); | ||||
| builder.Services.AddMemoryCache(); | ||||
| builder.Services.AddLogs(builder); | ||||
| builder.Services.AddMongoLayer(builder.Configuration); | ||||
| builder.Services.AddDALLayerServices(builder.Configuration); | ||||
|  | ||||
| builder.Host.ConfigureServices((context, services) => | ||||
| { | ||||
|  | ||||
| builder.Services.AddDALLayer(builder.Configuration); | ||||
|     services.AddLogging(); | ||||
|     services.AddControllers(); | ||||
|     services.AddProblemDetails(); | ||||
|     services.AddCors(options | ||||
|         => options.AddDefaultPolicy(policyBuilder | ||||
|             => policyBuilder | ||||
|                 .AllowAnyOrigin() | ||||
|                 .AllowAnyHeader() | ||||
|                 .AllowAnyMethod())); | ||||
|  | ||||
|     builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => | ||||
|     { | ||||
|         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||
|     }); | ||||
|  | ||||
|     services | ||||
|         .AddEndpointsApiExplorer() | ||||
|         .AddVersioning() | ||||
|         .AddSwagger(); | ||||
|  | ||||
|     services.AddHealthChecks(); | ||||
|     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||
|  | ||||
|     builder.Services.AddOutputCache(options => | ||||
|     { | ||||
|         options.AddBasePolicy(builder => | ||||
|             builder.Expire(TimeSpan.FromSeconds(10))); | ||||
|         options.AddPolicy("Expire20", builder => | ||||
|             builder.Expire(TimeSpan.FromSeconds(20))); | ||||
|         options.AddPolicy("Expire30", builder => | ||||
|             builder.Expire(TimeSpan.FromSeconds(30))); | ||||
|     }); | ||||
| }); | ||||
|  | ||||
| var app = builder.Build(); | ||||
|  | ||||
| app.UseSwaggerUI(builder.Configuration, authSettings); | ||||
| app.ConfigureSwagger(builder.Configuration); | ||||
| app.UseLogging(builder.Configuration); | ||||
| app.UseHttpsRedirection(); | ||||
| app.UseSwagger(); | ||||
| app.UseSwaggerUI(); | ||||
| app.UseAuthentication(); | ||||
| app.UseAuthorization(); | ||||
| app.MapControllers(); | ||||
| app.UseCors(); | ||||
| app.ConfigureSwagger(); | ||||
| app.UseHttpsRedirection(); | ||||
| app.UseStaticFiles(); | ||||
| app.UseRouting(); | ||||
| app.UseResponseCompression(); | ||||
| app.UseOutputCache(); | ||||
| app.UseResponseCaching(); | ||||
| app.UseLogging(builder.Configuration); | ||||
| app.MapHealthChecks("/health"); | ||||
|  | ||||
| app.Run(); | ||||
| app.Run(); | ||||
		Reference in New Issue
	
	Block a user
	 Oscar Morales
					Oscar Morales