-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (70 loc) · 2.65 KB
/
Copy pathProgram.cs
File metadata and controls
86 lines (70 loc) · 2.65 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
using apivendora.Data;
using Microsoft.EntityFrameworkCore;
using apivendora.Services.Inventario;
using apivendora.Services.Ventas;
using apivendora.Services.Productos;
using apivendora.Services.Usuarios;
using apivendora.Services.Finanzas;
using apivendora.Repositories.Productos;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Security.Cryptography.X509Certificates;
var builder = WebApplication.CreateBuilder(args);
// Agregar conexión MySQL
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseMySql(builder.Configuration.GetConnectionString("DefaultConnection"),
new MySqlServerVersion(new Version(8, 0, 36))));
// Agregar servicios
builder.Services.AddScoped<UsuarioService>();
builder.Services.AddScoped<BarrasService>();
builder.Services.AddScoped<CajeraService>();
builder.Services.AddScoped<ConsultaService>();
builder.Services.AddScoped<DefacturaService>();
builder.Services.AddScoped<FacturaService>();
builder.Services.AddScoped<FormapagoService>();
builder.Services.AddScoped<ImpuestoService>();
builder.Services.AddScoped<LaboratorioService>();
builder.Services.AddScoped<MformapagoService>();
builder.Services.AddScoped<MtransaccionService>();
builder.Services.AddScoped<ProductoService>();
builder.Services.AddScoped<ProveedorService>();
builder.Services.AddScoped<RecogidaService>();
builder.Services.AddScoped<SaldosService>();
builder.Services.AddScoped<TinventarioService>();
builder.Services.AddScoped<ILaboratorioRepository, LaboratorioRepository>();
builder.Services.AddScoped<IBarrasRepository, BarrasRepository>();
builder.Services.AddScoped<IProductoRepository, ProductoRepository>();
// Agregar controladores
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null; // Para mantener el formato original de las propiedades
});
//Escuchasr en puertos 5259 y 5260
// Habilitar HTTPS en el puerto 5260
// Habilitar HTTP en el puerto 5259
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5259); // HTTP normal
var cert = new X509Certificate2("/etc/ssl/apivendora/apivendora.pfx", "1234");
options.ListenAnyIP(5260, listenOptions =>
{
listenOptions.UseHttps(cert);
});
});
var app = builder.Build();
app.UseMiddleware<apivendora.Middleware.ErrorHandlingMiddleware>();
app.UseCors("AllowAllOrigins");
app.UseAuthorization();
app.MapControllers();
app.Run();