summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Program.cs27
1 files changed, 17 insertions, 10 deletions
diff --git a/Program.cs b/Program.cs
index 5863368..fdb899c 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,3 +1,4 @@
+using HyperBooru.Server.Components;
using HyperBooru.Services;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.DataProtection;
@@ -5,12 +6,12 @@ using Microsoft.AspNetCore.Http.Json;
using Microsoft.EntityFrameworkCore;
using System.Text.Json.Serialization;
-namespace HyperBooru;
+namespace HyperBooru.Server;
public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);
- builder.Services.AddSession();
+
builder.Services.AddHttpContextAccessor();
builder.Services.AddAuthentication(
CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
@@ -22,8 +23,8 @@ public class Program {
builder.Services.Configure<JsonOptions>(o => {
o.SerializerOptions.TypeInfoResolverChain.Insert(0, new ExceptionJsonResolver());
});
- builder.Services.AddRazorPages();
- builder.Services.AddServerSideBlazor();
+ builder.Services.AddRazorComponents()
+ .AddInteractiveWebAssemblyComponents();
// Add our custom services
builder.Services.AddSingleton<IConfigService, ConfigService>();
@@ -34,7 +35,6 @@ public class Program {
builder.Services.AddSingleton<IGlobalUserService, GlobalUserService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddHostedService<OcrService>();
- builder.Services.AddSingleton<ISourceService, SourceService>();
// Ensure session keys are stored in a persistent location on all platforms
builder.Services.AddDataProtection()
@@ -50,17 +50,24 @@ public class Program {
using var db = scope.ServiceProvider.GetRequiredService<HBContext>();
db.Database.Migrate();
- app.UseRouting();
- app.UseSession();
app.UseAuthentication();
app.UseAuthorization();
+ if(app.Environment.IsDevelopment()) {
+ app.UseWebAssemblyDebugging();
+ } else {
+ app.UseExceptionHandler("/Error");
+ }
+
+ app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseHsts();
app.UseHttpsRedirection();
- app.UseStaticFiles();
+ app.MapStaticAssets();
app.UseMiddleware<ExceptionMiddleware>();
- app.MapBlazorHub();
+ app.UseAntiforgery();
app.MapControllers();
- app.MapFallbackToPage("/_Host");
+ app.MapRazorComponents<App>()
+ .AddInteractiveWebAssemblyRenderMode()
+ .AddAdditionalAssemblies(typeof(Client._Imports).Assembly);
app.Run();
}