-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
95 lines (74 loc) · 2.36 KB
/
Copy pathProgram.cs
File metadata and controls
95 lines (74 loc) · 2.36 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
using ManageLife.Core;
using ManageLife.Data;
using ManageLife.Extensions;
using ManageLife.Hubs;
using ManageLife.Middleware;
using ManageLife.Services;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// ================== SERILOG ==================
var logPath = Path.Combine(AppContext.BaseDirectory, "Logs");
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}
builder.Host.UseSerilog((context, services, loggerConfig) =>
{
loggerConfig
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext();
});
// =============================================
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddSignalR();
// Add application services
builder.Services.AddApplicationServices(builder.Configuration);
// Cấu hình Kestrel (request body limit)
builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
});
builder.Services.AddHostedService<TelegramUploadWorker>();
var app = builder.Build();
await app.ApplyMigrationsAsync();
// ====== Serilog request logging ======
app.UseSerilogRequestLogging();
// =====================================
app.UseMapperBase();
// ======= SEED DATA =========
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var config = scope.ServiceProvider.GetRequiredService<IConfiguration>();
await Seed.SeedData(context, config);
// ======= REGISTER PERMISSIONS =========
var services = scope.ServiceProvider;
await services.RegisterPermissionsAsync(typeof(Program).Assembly);
// ======================================
}
// ===========================
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseMiddleware<JwtAuthenticationMiddleware>();
app.UseAuthorization();
app.MapControllerRoute(
name: "admin_default",
pattern: "Admin/{controller=Dashboard}/{action=Index}/{id?}",
defaults: new { area = "Admin" }
);
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);
app.MapHub<ChatHub>("/chathub");
app.Run();