Blog/Program.cs 2 K · 56 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. warframe.com blocks requests from
18 // the server, so the 4 MB page ships in Blog/Resources and scripts/update-droptables.sh refreshes
19 // it before a publish. Singleton: the parsed tables live in the service, so a transient one would
20 // re-parse per request - see WarframeDropService.
21 builder.Services.Configure<WarframeOptions>(builder.Configuration.GetSection(WarframeOptions.Section));
22 builder.Services.AddSingleton<WarframeDropService>();
23
24 // /rvrb reads the rvrb bot's stats straight off its BEAM, over Erlang distribution. The node this
25 // site dials with is started on the first request, not here - see RvrbService.
26 builder.Services.Configure<RvrbOptions>(builder.Configuration.GetSection(RvrbOptions.Section));
27 builder.Services.AddSingleton<RvrbService>();
28
29 // builder.Services.AddTransient<BrpService>();
30 // builder.Services.AddTransient<NsService>();
31
32 var app = builder.Build();
33
34 // Configure the HTTP request pipeline.
35 if (!app.Environment.IsDevelopment())
36 {
37 app.UseExceptionHandler("/Error", createScopeForErrors: true);
38 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
39 app.UseHsts();
40 }
41
42 app.UseHttpsRedirection();
43
44 app.UseAntiforgery();
45
46 app.MapStaticAssets();
47 app.MapRazorComponents<App>();
48
49 // Item names matching what has been typed, for the search box's suggestion list.
50 app.MapGet("/api/warframe/names", async (string? q, WarframeDropService drops, CancellationToken cancellationToken) =>
51 {
52 var status = await drops.GetTablesAsync(cancellationToken).ConfigureAwait(false);
53 return status.Tables?.Search(q ?? "", 10) ?? [];
54 });
55
56 app.Run();