diff options
| author | Jake Mannens <jake@asger.xyz> | 2026-05-22 00:52:16 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-05-23 22:22:55 +1000 |
| commit | 12eaa5814ef20b0910e8d64a753378b6f6797989 (patch) | |
| tree | 062cf477c29054e0f089cb80f0cd79a9f3b7ccd9 /Server/Program.cs | |
| parent | 6de5d7f5364fe1d54703da6d6b7cb08ea26e939f (diff) | |
Initial commitwasm-initial
Diffstat (limited to 'Server/Program.cs')
| -rw-r--r-- | Server/Program.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Server/Program.cs b/Server/Program.cs new file mode 100644 index 0000000..687c6f8 --- /dev/null +++ b/Server/Program.cs @@ -0,0 +1,73 @@ +using HyperBooru.ApiClient; +using HyperBooru.Server.Components; +using HyperBooru.Services; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.EntityFrameworkCore; +using System.Text.Json.Serialization; + +namespace HyperBooru.Server; + +public class Program { + public static void Main(string[] args) { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + builder.Services.AddHttpContextAccessor(); + builder.Services.AddControllers().AddJsonOptions(o => { + var converter = new JsonStringEnumConverter(); + o.JsonSerializerOptions.Converters.Add(converter); + }); + builder.Services.AddRazorComponents() + .AddInteractiveWebAssemblyComponents(); + + // Add our custom services + builder.Services.AddSingleton<IConfigService, ConfigService>(); + builder.Services.AddDbContextFactory<HBContext>(); + builder.Services.AddSingleton<IGlobalUserService, GlobalUserService>(); + builder.Services.AddScoped<IMediaService, MediaService>(); + builder.Services.AddScoped<IFeedService, FeedService>(); + builder.Services.AddScoped<ITagService, TagService>(); + builder.Services.AddScoped<IUserService, UserService>(); + builder.Services.AddHostedService<OcrService>(); + builder.Services.AddSingleton<ISourceService, SourceService>(); + builder.Services.AddSingleton(sp => new HBSession() { + BaseUri = new("https://127.0.0.1:7084") + }); + + // Ensure session keys are stored in a persistent location on all platforms + builder.Services.AddDataProtection() + .PersistKeysToFileSystem(new( + builder.Services.BuildServiceProvider() + .GetRequiredService<IConfigService>() + .KeyPath)); + + var app = builder.Build(); + + // Ensure database is created and it's schema is up to date + using var scope = app.Services.CreateScope(); + using var db = scope.ServiceProvider.GetRequiredService<HBContext>(); + db.Database.Migrate(); + + // Configure the HTTP request pipeline. + if(app.Environment.IsDevelopment()) { + app.UseWebAssemblyDebugging(); + } else { + 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.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); + app.UseHttpsRedirection(); + + app.UseAntiforgery(); + + app.MapStaticAssets(); + app.MapControllers(); + app.MapRazorComponents<App>() + .AddInteractiveWebAssemblyRenderMode() + .AddAdditionalAssemblies(typeof(Client._Imports).Assembly); + + app.Run(); + } +} |
