oliverbooth.dev/OliverBooth/Program.cs

101 lines
3.2 KiB
C#
Raw Normal View History

using AspNetCore.ReCaptcha;
using Markdig;
using OliverBooth.Data.Blog;
using OliverBooth.Data.Web;
using OliverBooth.Extensions;
using OliverBooth.Markdown;
using OliverBooth.Markdown.Callout;
using OliverBooth.Markdown.Template;
using OliverBooth.Markdown.Timestamp;
2023-08-06 14:56:08 +00:00
using OliverBooth.Services;
2023-08-12 20:06:48 +00:00
using Serilog;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs/latest.log", rollingInterval: RollingInterval.Day)
#if DEBUG
.MinimumLevel.Debug()
#endif
2023-08-12 20:06:48 +00:00
.CreateLogger();
2023-08-06 14:56:08 +00:00
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddTomlFile("data/config.toml", true, true);
2023-08-06 14:56:08 +00:00
builder.Logging.ClearProviders();
2023-08-12 20:06:48 +00:00
builder.Logging.AddSerilog();
2023-08-12 19:40:46 +00:00
builder.Services.AddSingleton(provider => new MarkdownPipelineBuilder()
.Use<TimestampExtension>()
.Use(new TemplateExtension(provider.GetRequiredService<ITemplateService>()))
// we have our own "alert blocks"
.UseCallouts()
// advanced extensions. add explicitly to avoid UseAlertBlocks
.UseAbbreviations()
.UseAutoIdentifiers()
.UseCitations()
.UseCustomContainers()
.UseDefinitionLists()
.UseEmphasisExtras()
.UseFigures()
.UseFooters()
.UseFootnotes()
.UseGridTables()
.UseMathematics()
.UseMediaLinks()
.UsePipeTables()
.UseListExtras()
.UseTaskLists()
.UseDiagrams()
.UseAutoLinks()
.UseGenericAttributes() // must be last as it is one parser that is modifying other parsers
// no more advanced extensions
.UseBootstrap()
.UseEmojiAndSmiley()
.UseSmartyPants()
.Build());
builder.Services.AddDbContextFactory<BlogContext>();
builder.Services.AddDbContextFactory<WebContext>();
2024-02-23 03:23:57 +00:00
builder.Services.AddHttpClient();
builder.Services.AddSingleton<ICodeSnippetService, CodeSnippetService>();
2023-12-22 14:26:18 +00:00
builder.Services.AddSingleton<IContactService, ContactService>();
builder.Services.AddSingleton<ITemplateService, TemplateService>();
builder.Services.AddSingleton<IBlogPostService, BlogPostService>();
builder.Services.AddSingleton<IBlogUserService, BlogUserService>();
builder.Services.AddSingleton<IProgrammingLanguageService, ProgrammingLanguageService>();
2023-09-24 13:36:36 +00:00
builder.Services.AddSingleton<IProjectService, ProjectService>();
2024-02-23 03:23:57 +00:00
builder.Services.AddSingleton<IMastodonService, MastodonService>();
2024-02-20 20:36:23 +00:00
builder.Services.AddSingleton<ITutorialService, TutorialService>();
2023-12-14 16:03:24 +00:00
builder.Services.AddSingleton<IReadingListService, ReadingListService>();
2023-08-06 14:55:12 +00:00
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
2023-08-05 20:01:47 +00:00
builder.Services.AddControllersWithViews();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
builder.Services.AddReCaptcha(builder.Configuration.GetSection("ReCaptcha"));
2023-05-26 18:05:44 +00:00
if (builder.Environment.IsProduction())
{
builder.WebHost.AddCertificateFromEnvironment(2845, 5049);
}
2023-08-10 22:33:15 +00:00
WebApplication app = builder.Build();
2023-05-26 18:05:44 +00: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 19:06:05 +00:00
app.UseStatusCodePagesWithRedirects("/error/{0}");
2023-05-26 18:05:44 +00:00
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
2023-08-05 19:58:03 +00:00
2023-08-05 20:01:47 +00:00
app.MapControllers();
2023-05-26 18:05:44 +00:00
app.MapRazorPages();
app.Run();