-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (70 loc) · 2.91 KB
/
Program.cs
File metadata and controls
89 lines (70 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using Hangfire;
using HealthCenterAPI.Application.Services;
using HealthCenterAPI.Domain.Contracts.IRepository;
using HealthCenterAPI.Domain.Contracts.IServices;
using HealthCenterAPI.Extencion;
using HealthCenterAPI.Infrastructure.Repository;
using HealthCenterAPI.Presentation.Mapping;
using HealthCenterAPI.Shared.Utils;
using Microsoft.AspNetCore.HttpOverrides;
using Newtonsoft.Json.Serialization;
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureDbPostgreSQL(builder.Configuration);
builder.Services.ConfigureIISIntegration();
builder.Services.ConfigureHangFire(builder.Configuration);
builder.Services.ConfigureBackgroundJobs();
builder.Services.AddAutoMapper(typeof(MappingProfile));
builder.Services.AddTransient<WebScrapingSNS>();
builder.Services.AddScoped<IFileRepository, FileRepository>();
builder.Services.AddScoped<IFileServices, FileServices>();
builder.Services.AddScoped<IHealthCenterServices, HealthCenterServices>();
builder.Services.AddScoped<IHealthCenterRepository, HealthCenterRepository>();
builder.Services.AddOpenApi();
builder.Services.AddMemoryCache();
builder.Services.ConfigurationCords(builder.Configuration);
builder.Services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsProduction())
{
app.UseHsts(); // Habilitar HSTS (HTTP Strict Transport Security)
// A�adir encabezados de seguridad
app.Use(async (context, next) =>
{
context.Response.Headers["X-Content-Type-Options"] = "nosniff";
context.Response.Headers["Referrer-Policy"] = "no-referrer";
context.Response.Headers["X-XSS-Protection"] = "1; mode=block";
context.Response.Headers["Content-Security-Policy"] = "default-src 'none'; frame-ancestors 'none'; script-src 'none';"; // Restrict APIs
await next();
});
app.UseHttpsRedirection();
}
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
});
// Activar el dashboard de Hangfire solo en entorno de desarrollo
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
// Configurar Scalar para la interfaz de usuario
app.MapScalarApiReference(options =>
{
options.WithTitle("HealthCenterAPI")
.WithDownloadButton(false)
.WithTheme(ScalarTheme.Purple)
.WithDefaultHttpClient(ScalarTarget.JavaScript, ScalarClient.Axios);
});
app.UseHangfireDashboard();
}
app.UseCors("CorsPolicy");
app.UseRouting();
app.MapControllers();
app.Run();