Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (43 loc) · 1.71 KB
/
Copy pathProgram.cs
File metadata and controls
58 lines (43 loc) · 1.71 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
using Microsoft.EntityFrameworkCore;
using TuneMates_Backend.BackgroundServices;
using TuneMates_Backend.DataBase;
using TuneMates_Backend.Infrastructure.Auth;
using TuneMates_Backend.Infrastructure.Cors;
using TuneMates_Backend.Infrastructure.RateLimiting;
using TuneMates_Backend.Route;
var builder = WebApplication.CreateBuilder(args);
// Add JWT Authentication services
builder.Services.AddAppJwtAuthentication(builder.Configuration);
// Add DbContext with PostgreSQL provider
builder.Services.AddDbContext<AppDbContext>(opts => opts.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
// Add Cron Jobs as background services
builder.Services.AddHostedService<TokenCleanupService>();
builder.Services.AddHostedService<ProposalCleanupService>();
builder.Services.AddHostedService<RoomCleanupService>();
builder.Services.AddHostedService<SpotifyStateCleanupService>();
builder.Services.AddHostedService<RoomCodeCleanupService>();
// Add Memory Cache
builder.Services.AddMemoryCache();
// Register JwtTokenService
builder.Services.Configure<JwtSettings>(builder.Configuration.GetSection("Jwt"));
builder.Services.AddSingleton<JwtTokenService>();
// Configure CORS
builder.Services.AddAppCors(builder.Configuration);
// Configure Rate Limiting
builder.Services.AddAppRateLimiting(builder.Configuration);
// Build the application.
var app = builder.Build();
// Activate CORS middleware
app.UseAppCors();
// Activate Rate Limiting middleware
app.UseAppRateLimiting();
// Activate JWT Authentication middleware
app.UseAppJwtAuthentication();
// Map API routes
var api = app.MapGroup("/api");
api.MapUserRoutes();
api.MapRoomRoutes();
api.MapSongRoutes();
api.MapSpotifyRoutes();
// Launch the application.
app.Run();