From 0a61b50e301a0cc90b7974f4b2bb84212cbf9307 Mon Sep 17 00:00:00 2001 From: Sakura Akeno Isayeki Date: Sun, 14 Jan 2024 11:59:05 +0100 Subject: [PATCH] feat: Add InteractiveAutoRenderMode to App.razor - Added `@rendermode="new InteractiveAutoRenderMode()"` to the `` component in `App.razor`. --- SocialGuard.Web/App.razor | 2 +- SocialGuard.Web/Startup.cs | 131 +++++++++++++++++++------------------ 2 files changed, 67 insertions(+), 66 deletions(-) diff --git a/SocialGuard.Web/App.razor b/SocialGuard.Web/App.razor index 6f67a6e..8e86f23 100644 --- a/SocialGuard.Web/App.razor +++ b/SocialGuard.Web/App.razor @@ -1,4 +1,4 @@ - + diff --git a/SocialGuard.Web/Startup.cs b/SocialGuard.Web/Startup.cs index 49e900a..c22580b 100644 --- a/SocialGuard.Web/Startup.cs +++ b/SocialGuard.Web/Startup.cs @@ -6,94 +6,95 @@ using Microsoft.Extensions.Hosting; using SocialGuard.Web.Services; using SocialGuard.Web.Services.Logging; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using Nodsoft.MoltenObsidian.Blazor; -namespace SocialGuard.Web +namespace SocialGuard.Web; + +public sealed class Startup { - public class Startup + public Startup(IConfiguration configuration) { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } + Configuration = configuration; + } - public IConfiguration Configuration { get; } + public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - services.AddRazorPages(); - services.AddServerSideBlazor(); - services.AddDistributedMemoryCache(); - services.AddDirectoryBrowser(); + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services.AddRazorPages(); + + services.AddServerSideBlazor() + .AddInteractiveServerComponents(); + + services.AddDistributedMemoryCache(); + services.AddDirectoryBrowser(); - // Add the MoltenObsidian Vault - services.AddHttpClient("Docs", client => client.BaseAddress = new(Configuration["Docs:WebRoot"])); - services.AddMoltenObsidianHttpVault(static services => services.GetRequiredService().CreateClient("Docs")); - services.AddMoltenObsidianBlazorIntegration(); + // Add the MoltenObsidian Vault + services.AddHttpClient("Docs", client => client.BaseAddress = new(Configuration["Docs:WebRoot"])); + services.AddMoltenObsidianHttpVault(static services => services.GetRequiredService().CreateClient("Docs")); + services.AddMoltenObsidianBlazorIntegration(); - services.AddCors(c => c.AddDefaultPolicy(builder => builder - .AllowAnyOrigin() - .AllowAnyHeader() - .AllowAnyMethod())); + services.AddCors(c => c.AddDefaultPolicy(builder => builder + .AllowAnyOrigin() + .AllowAnyHeader() + .AllowAnyMethod())); - services.AddSingleton(); - } + services.AddSingleton(); + } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else if (env.IsProduction()) + app.UseDeveloperExceptionPage(); + } + else if (env.IsProduction()) + { + IPAddress[] allowedProxies = Configuration.GetSection("AllowedProxies").Get()?.Select(IPAddress.Parse).ToArray() ?? []; + + // Nginx configuration step + ForwardedHeadersOptions forwardedHeadersOptions = new() { - IEnumerable allowedProxies = Configuration.GetSection("AllowedProxies")?.Get()?.Select(x => IPAddress.Parse(x)); + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }; - // Nginx configuration step - ForwardedHeadersOptions forwardedHeadersOptions = new() - { - ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto - }; + if (allowedProxies is { Length: not 0 }) + { + forwardedHeadersOptions.KnownProxies.Clear(); - if (allowedProxies is not null && allowedProxies.Any()) + foreach (IPAddress address in allowedProxies) { - forwardedHeadersOptions.KnownProxies.Clear(); - - foreach (IPAddress address in allowedProxies) - { - forwardedHeadersOptions.KnownProxies.Add(address); - } + forwardedHeadersOptions.KnownProxies.Add(address); } - - app.UseExceptionHandler("/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.UseExceptionHandler("/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.UseHttpsRedirection(); - app.UseMiddleware(); + app.UseMiddleware(); - app.UseStaticFiles(); - // app.UseStaticFiles("/viewer"); - // app.UseBlazorFrameworkFiles("/viewer"); + app.UseStaticFiles(); + // app.UseStaticFiles("/viewer"); + // app.UseBlazorFrameworkFiles("/viewer"); - app.UseRouting(); - app.UseCors(); + app.UseRouting(); + app.UseCors(); - app.UseEndpoints(endpoints => - { - endpoints.MapBlazorHub(); - endpoints.MapFallbackToFile("/viewer/{*path:nonfile}", "viewer/index.html"); - endpoints.MapFallbackToPage("/_Host"); - }); - } + app.UseEndpoints(endpoints => + { + endpoints.MapBlazorHub(); + endpoints.MapFallbackToFile("/viewer/{*path:nonfile}", "viewer/index.html"); + endpoints.MapFallbackToPage("/_Host"); + }); } -} +} \ No newline at end of file