-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
96 lines (80 loc) · 3.31 KB
/
Program.cs
File metadata and controls
96 lines (80 loc) · 3.31 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
88
89
90
91
92
93
94
95
96
using APKVersionControlAPI.Extencions;
using APKVersionControlAPI.Infrastructure;
using APKVersionControlAPI.Infrastructure.Repository;
using APKVersionControlAPI.Interfaces.IRepository;
using APKVersionControlAPI.Interfaces.IServices;
using APKVersionControlAPI.Services;
using Hangfire;
using Hangfire.MemoryStorage;
using HealthCenterAPI.Extencion;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Serialization;
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Agregar SqlLiteContext al contenedor de servicios
builder.Services.AddDbContext<SqlLiteContext>(options =>
options.UseSqlite($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "apkVersing.db")}"));
builder.Services.ConfigureMaxRequestBodySize(2L * 1024 * 1024 * 1024); // 2 GB
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.Configure<IISOptions>(options => { });
builder.Services.AddHangfire(config => config.UseMemoryStorage());
builder.Services.AddScoped<IAPKVersionControlServices, APKVersionControlServices>();
builder.Services.AddScoped<IApkFileRepository, ApkFileRepository>();
builder.Services.ConfigureBackgroundJobs();
builder.Services.AddHangfireServer();
builder.Services.AddOpenApi();
builder.Services.ConfigureCords(builder.Configuration);
builder.Services.ConfigureNewtonsoftJsonForControllers();
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();
}
string webRootPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()!.Location)!, "wwwroot");
if (!Directory.Exists(webRootPath))
{
Directory.CreateDirectory(webRootPath);
}
// Asegura que la base de datos esté creada
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<SqlLiteContext>();
dbContext.Database.EnsureCreated(); // Crea la base de datos y las tablas si no existen
}
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
// Configurar Scalar para la interfaz de usuario
app.MapScalarApiReference(options =>
{
options.WithTitle("APKVersionControl")
.WithDownloadButton(false)
.WithTheme(ScalarTheme.Purple)
.WithDefaultHttpClient(ScalarTarget.JavaScript, ScalarClient.Axios);
});
app.UseHangfireDashboard();
}
SQLitePCL.Batteries.Init();
app.UseCors("CorsPolicy");
app.UseRouting();
app.MapControllers();
app.Run();