-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (27 loc) · 828 Bytes
/
Program.cs
File metadata and controls
36 lines (27 loc) · 828 Bytes
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
using TJ_API.Services;
using TJ_API.Models;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Setup logging
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
// Setup rate limits
RateLimiterService.RateLimitInit(builder);
// Setup Swagger docs
SwaggerHandler.BuilderInit(builder);
WebApplication app = builder.Build();
app.UseRouting();
// Let's not provide the blueprint to our API to hackers! 👻
if (app.Environment.IsDevelopment())
{
SwaggerHandler.Run(app);
}
app.MapControllers();
app.UseRateLimiter();
app.MapFallback(async ctx =>
{
ctx.Response.StatusCode = 500;
app.Logger.LogError("Internal Server Error!");
await ctx.Response.WriteAsJsonAsync(new ErrorMessage("Muja! Check your arguments. Monnimoka."));
});
app.Run();