Skip to content

Commit

Permalink
feat: Add InteractiveAutoRenderMode to App.razor
Browse files Browse the repository at this point in the history
- Added `@rendermode="new InteractiveAutoRenderMode()"` to the `<Router>` component in `App.razor`.
  • Loading branch information
SakuraIsayeki committed Jan 14, 2024
1 parent b537638 commit 0a61b50
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion SocialGuard.Web/App.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Router @rendermode="new InteractiveAutoRenderMode()" AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
Expand Down
131 changes: 66 additions & 65 deletions SocialGuard.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHttpClientFactory>().CreateClient("Docs"));
services.AddMoltenObsidianBlazorIntegration();
// Add the MoltenObsidian Vault
services.AddHttpClient("Docs", client => client.BaseAddress = new(Configuration["Docs:WebRoot"]));
services.AddMoltenObsidianHttpVault(static services => services.GetRequiredService<IHttpClientFactory>().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<PageContentLoader>();
}
services.AddSingleton<PageContentLoader>();
}

// 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<string[]>()?.Select(IPAddress.Parse).ToArray() ?? [];

// Nginx configuration step
ForwardedHeadersOptions forwardedHeadersOptions = new()
{
IEnumerable<IPAddress> allowedProxies = Configuration.GetSection("AllowedProxies")?.Get<string[]>()?.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<RequestLoggingMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();

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");
});
}
}
}

0 comments on commit 0a61b50

Please sign in to comment.