- Adds a new `MercadosFeriados` table to the database to persist market holidays.
- Implements `HolidayDataFetcher` to update holidays weekly from Finnhub API.
- Implements `IHolidayService` with in-memory caching to check for holidays efficiently.
- Worker service now skips fetcher execution on market holidays.
- Adds a new API endpoint `/api/mercados/es-feriado/{mercado}`.
- Integrates a non-blocking holiday alert into the `BolsaLocalWidget`."
93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
using FluentMigrator.Runner;
|
|
using Mercados.Database.Migrations;
|
|
using Mercados.Infrastructure;
|
|
using Mercados.Infrastructure.Persistence;
|
|
using Mercados.Infrastructure.Persistence.Repositories;
|
|
using Mercados.Api.Utils;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Mercados.Infrastructure.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Nombre para política de CORS
|
|
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
|
|
|
// Añadimos el servicio de CORS
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(name: MyAllowSpecificOrigins,
|
|
policy =>
|
|
{
|
|
policy.WithOrigins("http://localhost:5173",
|
|
"http://192.168.10.78:5173",
|
|
"https://www.eldia.com",
|
|
"https://extras.eldia.com")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod();
|
|
});
|
|
});
|
|
|
|
// Registros de servicios (esto está perfecto)
|
|
builder.Services.AddSingleton<IDbConnectionFactory, SqlConnectionFactory>();
|
|
builder.Services.AddScoped<ICotizacionGanadoRepository, CotizacionGanadoRepository>();
|
|
builder.Services.AddScoped<ICotizacionGranoRepository, CotizacionGranoRepository>();
|
|
builder.Services.AddScoped<ICotizacionBolsaRepository, CotizacionBolsaRepository>();
|
|
builder.Services.AddScoped<IFuenteDatoRepository, FuenteDatoRepository>();
|
|
builder.Services.AddScoped<IMercadoFeriadoRepository, MercadoFeriadoRepository>();
|
|
builder.Services.AddMemoryCache();
|
|
builder.Services.AddScoped<IMercadoFeriadoRepository, MercadoFeriadoRepository>();
|
|
builder.Services.AddScoped<IHolidayService, FinnhubHolidayService>();
|
|
|
|
// Configuración de FluentMigrator (perfecto)
|
|
builder.Services
|
|
.AddFluentMigratorCore()
|
|
.ConfigureRunner(rb => rb
|
|
.AddSqlServer()
|
|
.WithGlobalConnectionString(builder.Configuration.GetConnectionString("DefaultConnection"))
|
|
.ScanIn(typeof(CreateInitialTables).Assembly).For.Migrations())
|
|
.AddLogging(lb => lb.AddFluentMigratorConsole());
|
|
|
|
|
|
builder.Services.AddControllers()
|
|
.AddJsonOptions(options =>
|
|
{
|
|
// Añadimos nuestro convertidor personalizado para manejar las fechas.
|
|
options.JsonSerializerOptions.Converters.Add(new UtcDateTimeConverter());
|
|
});
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
|
{
|
|
options.ForwardedHeaders =
|
|
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
|
// En un entorno de producción real, deberías limitar esto a las IPs de tus proxies.
|
|
// options.KnownProxies.Add(IPAddress.Parse("192.168.5.X")); // IP de tu NPM
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Le decimos a la aplicación que USE el middleware de cabeceras de reenvío.
|
|
// ¡El orden importa! Debe ir antes de UseHttpsRedirection y UseCors.
|
|
app.UseForwardedHeaders();
|
|
|
|
// Ejecución de migraciones (perfecto)
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var migrationRunner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
|
|
migrationRunner.MigrateUp();
|
|
}
|
|
|
|
// Pipeline de HTTP (perfecto)
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseCors(MyAllowSpecificOrigins);
|
|
app.UseAuthorization();
|
|
app.MapControllers();
|
|
app.Run(); |