-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (67 loc) · 2.45 KB
/
Program.cs
File metadata and controls
82 lines (67 loc) · 2.45 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
using System.Threading.RateLimiting;
using InterServer.Controllers;
using InterServer.Logic;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.RateLimiting;
var builder = WebApplication.CreateBuilder(args);
// Thing to make JSON case-sensitive, unused for now. Breaks some things
// builder.Services.AddControllers()
// .AddJsonOptions(options =>
// {
// options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
// options.JsonSerializerOptions.PropertyNamingPolicy = null;
// });
// Add services to the container.
builder.Services.AddControllersWithViews();
// API versioning and such
builder.Services.AddApiVersioning(opt =>
{
opt.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1,0);
opt.AssumeDefaultVersionWhenUnspecified = true;
opt.ReportApiVersions = true;
opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("x-api-version"),
new MediaTypeApiVersionReader("x-api-version"));
});
builder.Services.AddRateLimiter(_ => _
.AddFixedWindowLimiter(policyName: "fixed", options =>
{
options.PermitLimit = 10;
options.Window = TimeSpan.FromSeconds(12);
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
options.QueueLimit = 5;
}));
// Background services
builder.Services.AddSingleton<DataCollector>();
builder.Services.AddHostedService<DataCollector>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
string pathPrefix = "";
try
{
AppSettings settings = new SettingsController().GetSettings();
pathPrefix = settings.PathPrefix;
}
catch (Exception e)
{
app.Logger.LogWarning("[Boot] Settings don't exist.");
// throw;
}
// app.UsePathBase("/"+pathPrefix+"/wwwroot");
app.UsePathBase("/wwwroot");
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
// IDK if I should touch that, it's been a while and I got no idea from where the {prefix} is coming from
pattern: String.IsNullOrEmpty(pathPrefix)? "{controller=Home}/{action=Index}/{id?}" : "{prefix?}/{controller=Home}/{action=Index}/{id?}");
app.UseRateLimiter();
app.Run();