Blog/Program.cs 2.2 K · 61 lines · raw · history

1 using Blog.Components;
2 using Blog.Services;
3
4 var builder = WebApplication.CreateBuilder(args);
5
6 // Add services to the container.
7 builder.Services.AddRazorComponents();
8
9 builder.Services.AddHttpClient();
10 builder.Services.AddHybridCache();
11 builder.Services.AddHttpClient<BrpService>(
12 client =>
13 {
14 client.BaseAddress = new Uri("https://brp.bes.is/");
15 });
16
17 // /Warframe searches Digital Extremes' published drop tables: 4 MB of HTML, updated a few times a
18 // month, parsed once and held in memory - see WarframeDropService.
19 builder.Services.Configure<WarframeOptions>(builder.Configuration.GetSection(WarframeOptions.Section));
20 builder.Services.AddHttpClient(WarframeDropService.ClientName, client =>
21 {
22 // The page is served off a CDN; identify the caller rather than asking for 4 MB anonymously.
23 client.DefaultRequestHeaders.UserAgent.ParseAdd("bes.is-droptables/1.0 (+https://bes.is/Warframe)");
24 });
25
26 // Singleton: the parsed tables live in the service, so a transient one would re-parse per request.
27 builder.Services.AddSingleton<WarframeDropService>();
28
29 // /rvrb reads the rvrb bot's stats straight off its BEAM, over Erlang distribution. The node this
30 // site dials with is started on the first request, not here - see RvrbService.
31 builder.Services.Configure<RvrbOptions>(builder.Configuration.GetSection(RvrbOptions.Section));
32 builder.Services.AddSingleton<RvrbService>();
33
34 // builder.Services.AddTransient<BrpService>();
35 // builder.Services.AddTransient<NsService>();
36
37 var app = builder.Build();
38
39 // Configure the HTTP request pipeline.
40 if (!app.Environment.IsDevelopment())
41 {
42 app.UseExceptionHandler("/Error", createScopeForErrors: true);
43 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
44 app.UseHsts();
45 }
46
47 app.UseHttpsRedirection();
48
49 app.UseAntiforgery();
50
51 app.MapStaticAssets();
52 app.MapRazorComponents<App>();
53
54 // Item names matching what has been typed, for the search box's suggestion list.
55 app.MapGet("/api/warframe/names", async (string? q, WarframeDropService drops, CancellationToken cancellationToken) =>
56 {
57 var status = await drops.GetTablesAsync(cancellationToken).ConfigureAwait(false);
58 return status.Tables?.Search(q ?? "", 10) ?? [];
59 });
60
61 app.Run();