-
Notifications
You must be signed in to change notification settings - Fork 396
/
Program.cs
52 lines (37 loc) · 1.34 KB
/
Program.cs
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
var builder = WebApplication.CreateBuilder(args);
// Configure auth
builder.AddAuthentication();
builder.Services.AddAuthorizationBuilder().AddCurrentUserHandler();
// Add the service to generate JWT tokens
builder.Services.AddTokenService();
// Configure the database
var connectionString = builder.Configuration.GetConnectionString("Todos") ?? "Data Source=.db/Todos.db";
builder.Services.AddSqlite<TodoDbContext>(connectionString);
// Configure identity
builder.Services.AddIdentityCore<TodoUser>()
.AddEntityFrameworkStores<TodoDbContext>();
// State that represents the current user from the database *and* the request
builder.Services.AddCurrentUser();
// Configure Open API
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(o => o.InferSecuritySchemes());
// Configure rate limiting
builder.Services.AddRateLimiting();
// Configure OpenTelemetry
builder.AddOpenTelemetry();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseRateLimiter();
app.Map("/", () => Results.Redirect("/swagger"));
// Configure the APIs
app.MapTodos();
app.MapUsers();
// Configure the prometheus endpoint for scraping metrics
app.MapPrometheusScrapingEndpoint();
// NOTE: This should only be exposed on an internal port!
// .RequireHost("*:9100");
app.Run();