| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | // backend/src/Titulares.Api/Program.cs | 
					
						
							|  |  |  | using Titulares.Api.Data; | 
					
						
							| 
									
										
										
										
											2025-10-28 12:56:42 -03:00
										 |  |  | using Titulares.Api.Hubs; | 
					
						
							|  |  |  | using Titulares.Api.Models; | 
					
						
							|  |  |  | using Titulares.Api.Services; | 
					
						
							|  |  |  | using Titulares.Api.Workers; | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var builder = WebApplication.CreateBuilder(args); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:56:42 -03:00
										 |  |  | builder.Configuration.AddJsonFile("configuracion.json", optional: false, reloadOnChange: true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | // Add services to the container. | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | builder.Services.AddControllers(); | 
					
						
							|  |  |  | builder.Services.AddEndpointsApiExplorer(); | 
					
						
							|  |  |  | builder.Services.AddSwaggerGen(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:56:42 -03:00
										 |  |  | builder.Services.Configure<ConfiguracionApp>(builder.Configuration); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | // Añadimos nuestro repositorio personalizado | 
					
						
							|  |  |  | builder.Services.AddSingleton<TitularRepositorio>(); | 
					
						
							| 
									
										
										
										
											2025-10-28 12:56:42 -03:00
										 |  |  | builder.Services.AddScoped<ScrapingService>(); | 
					
						
							| 
									
										
										
										
											2025-10-28 13:19:24 -03:00
										 |  |  | builder.Services.AddScoped<CsvService>(); | 
					
						
							| 
									
										
										
										
											2025-10-29 11:36:20 -03:00
										 |  |  | builder.Services.AddSingleton<ConfiguracionRepositorio>(); | 
					
						
							|  |  |  | builder.Services.AddSingleton<EstadoProcesoService>(); | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Añadimos la política de CORS | 
					
						
							|  |  |  | builder.Services.AddCors(options => | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     options.AddPolicy("AllowReactApp", builder => | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-10-29 14:47:21 -03:00
										 |  |  |         //builder.WithOrigins("http://localhost:5173") | 
					
						
							|  |  |  |         builder.AllowAnyOrigin() | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  |                .AllowAnyHeader() | 
					
						
							|  |  |  |                .AllowAnyMethod() | 
					
						
							|  |  |  |                .AllowCredentials(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | builder.Services.AddSignalR(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:56:42 -03:00
										 |  |  | builder.Services.AddHostedService<ProcesoScrapingWorker>(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | // Añadimos los servicios de autorización (necesario para app.UseAuthorization) | 
					
						
							|  |  |  | builder.Services.AddAuthorization(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | // 2. Construir la aplicación. | 
					
						
							|  |  |  | // ========================== | 
					
						
							|  |  |  | var app = builder.Build(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 3. Configurar el pipeline de peticiones HTTP. | 
					
						
							|  |  |  | // ============================================ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (app.Environment.IsDevelopment()) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     app.UseSwagger(); | 
					
						
							|  |  |  |     app.UseSwaggerUI(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | // COMENTAMOS LA REDIRECCIÓN HTTPS PORQUE TRABAJAMOS CON HTTP | 
					
						
							|  |  |  | // app.UseHttpsRedirection(); | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | // 1. Activa el enrutamiento para que la app sepa a dónde va la petición. | 
					
						
							|  |  |  | app.UseRouting(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 2. APLICA LA POLÍTICA DE CORS. | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | app.UseCors("AllowReactApp"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | // 3. Usamos la autorización. | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | app.UseAuthorization(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | // 4. Mapeamos los endpoints (Controladores y Hubs). | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | app.MapControllers(); | 
					
						
							| 
									
										
										
										
											2025-10-28 12:26:49 -03:00
										 |  |  | app.MapHub<TitularesHub>("/titularesHub"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-28 11:33:28 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | app.Run(); |