oliverbooth.dev/OliverBooth/Program.cs

86 lines
2.9 KiB
C#
Raw Normal View History

2024-02-25 15:40:58 +00:00
using Asp.Versioning;
using AspNetCore.ReCaptcha;
using Markdig;
using OliverBooth.Data.Blog;
using OliverBooth.Data.Web;
using OliverBooth.Extensions;
using OliverBooth.Markdown.Template;
using OliverBooth.Markdown.Timestamp;
2023-08-06 15:56:08 +01:00
using OliverBooth.Services;
2023-08-12 21:06:48 +01:00
using Serilog;
using X10D.Hosting.DependencyInjection;
2023-08-12 21:06:48 +01:00
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs/latest.log", rollingInterval: RollingInterval.Day)
#if DEBUG
.MinimumLevel.Debug()
#endif
2023-08-12 21:06:48 +01:00
.CreateLogger();
2023-08-06 15:56:08 +01:00
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddTomlFile("data/config.toml", true, true);
2023-08-06 15:56:08 +01:00
builder.Logging.ClearProviders();
2023-08-12 21:06:48 +01:00
builder.Logging.AddSerilog();
2023-08-12 20:40:46 +01:00
builder.Services.AddSingleton(provider => new MarkdownPipelineBuilder()
.Use<TimestampExtension>()
.Use(new TemplateExtension(provider.GetRequiredService<ITemplateService>()))
.UseAdvancedExtensions()
.UseBootstrap()
.UseEmojiAndSmiley()
.UseSmartyPants()
.Build());
2024-02-25 15:40:58 +00:00
builder.Services.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1);
options.ReportApiVersions = true;
options.ApiVersionReader = new UrlSegmentApiVersionReader();
});
builder.Services.AddDbContextFactory<BlogContext>();
builder.Services.AddDbContextFactory<WebContext>();
2024-02-23 03:23:57 +00:00
builder.Services.AddHttpClient();
2023-12-22 14:26:18 +00:00
builder.Services.AddSingleton<IContactService, ContactService>();
builder.Services.AddSingleton<ITemplateService, TemplateService>();
builder.Services.AddSingleton<IBlogPostService, BlogPostService>();
2023-09-24 14:36:36 +01:00
builder.Services.AddSingleton<IProjectService, ProjectService>();
2024-02-23 03:23:57 +00:00
builder.Services.AddSingleton<IMastodonService, MastodonService>();
2023-12-14 16:03:24 +00:00
builder.Services.AddSingleton<IReadingListService, ReadingListService>();
2024-02-25 17:21:29 +00:00
builder.Services.AddHostedSingleton<IUserService, UserService>();
builder.Services.AddHostedSingleton<ISessionService, SessionService>();
2023-08-06 15:55:12 +01:00
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
2023-08-05 21:01:47 +01:00
builder.Services.AddControllersWithViews();
2024-02-27 19:49:42 +00:00
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddServerSideBlazor().AddInteractiveServerComponents();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
builder.Services.AddReCaptcha(builder.Configuration.GetSection("ReCaptcha"));
2023-05-26 19:05:44 +01:00
if (builder.Environment.IsProduction())
{
builder.WebHost.AddCertificateFromEnvironment(2845, 5049);
}
2023-08-10 23:33:15 +01:00
WebApplication app = builder.Build();
2023-05-26 19:05:44 +01:00
if (!app.Environment.IsDevelopment())
{
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();
2023-09-25 20:06:05 +01:00
app.UseStatusCodePagesWithRedirects("/error/{0}");
2023-05-26 19:05:44 +01:00
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
2023-08-05 20:58:03 +01:00
2023-08-05 21:01:47 +01:00
app.MapControllers();
2023-05-26 19:05:44 +01:00
app.MapRazorPages();
2024-02-27 19:49:42 +00:00
app.MapBlazorHub();
2023-05-26 19:05:44 +01:00
app.Run();