2023-08-08 00:34:15 +01:00
|
|
|
using Markdig;
|
2023-08-10 22:49:44 +01:00
|
|
|
using NLog;
|
2023-08-06 15:56:08 +01:00
|
|
|
using NLog.Extensions.Logging;
|
2023-08-12 18:35:57 +01:00
|
|
|
using OliverBooth.Common.Extensions;
|
2023-08-06 15:57:23 +01:00
|
|
|
using OliverBooth.Data;
|
2023-08-11 16:35:06 +01:00
|
|
|
using OliverBooth.Markdown.Template;
|
2023-08-10 01:49:09 +01:00
|
|
|
using OliverBooth.Markdown.Timestamp;
|
2023-08-09 21:08:57 +01:00
|
|
|
using OliverBooth.Middleware;
|
2023-08-06 15:56:08 +01:00
|
|
|
using OliverBooth.Services;
|
|
|
|
using X10D.Hosting.DependencyInjection;
|
|
|
|
|
2023-08-04 00:38:44 +01:00
|
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
2023-08-06 15:57:23 +01:00
|
|
|
builder.Configuration.AddTomlFile("data/config.toml", true, true);
|
2023-05-26 19:05:44 +01:00
|
|
|
|
2023-08-06 15:56:08 +01:00
|
|
|
builder.Logging.ClearProviders();
|
|
|
|
builder.Logging.AddNLog();
|
|
|
|
builder.Services.AddHostedSingleton<LoggingService>();
|
2023-08-09 21:08:57 +01:00
|
|
|
builder.Services.AddSingleton<ConfigurationService>();
|
2023-08-08 21:03:41 +01:00
|
|
|
builder.Services.AddSingleton<TemplateService>();
|
2023-08-12 18:35:57 +01:00
|
|
|
builder.Services.AddHostedSingleton<BlogSessionService>();
|
2023-08-12 14:24:27 +01:00
|
|
|
builder.Services.AddSingleton<BlogUserService>();
|
2023-08-08 21:03:41 +01:00
|
|
|
|
|
|
|
builder.Services.AddSingleton(provider => new MarkdownPipelineBuilder()
|
2023-08-10 01:49:09 +01:00
|
|
|
.Use<TimestampExtension>()
|
2023-08-09 23:19:19 +01:00
|
|
|
.Use(new TemplateExtension(provider.GetRequiredService<TemplateService>()))
|
2023-08-08 00:34:15 +01:00
|
|
|
.UseAdvancedExtensions()
|
|
|
|
.UseBootstrap()
|
2023-08-09 23:19:39 +01:00
|
|
|
.UseEmojiAndSmiley()
|
2023-08-09 23:19:29 +01:00
|
|
|
.UseSmartyPants()
|
2023-08-08 00:34:15 +01:00
|
|
|
.Build());
|
2023-08-06 15:56:08 +01:00
|
|
|
|
2023-08-06 15:57:23 +01:00
|
|
|
builder.Services.AddDbContextFactory<BlogContext>();
|
|
|
|
builder.Services.AddDbContextFactory<WebContext>();
|
2023-08-08 01:30:32 +01:00
|
|
|
builder.Services.AddSingleton<BlogService>();
|
2023-08-06 15:55:12 +01:00
|
|
|
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
|
2023-08-05 21:01:47 +01:00
|
|
|
builder.Services.AddControllersWithViews();
|
2023-08-11 17:16:26 +01:00
|
|
|
builder.Services.AddCors(options => options.AddPolicy("BlogApi", policy => (builder.Environment.IsDevelopment()
|
|
|
|
? policy.AllowAnyOrigin()
|
|
|
|
: policy.WithOrigins("https://oliverbooth.dev"))
|
|
|
|
.AllowAnyMethod()
|
|
|
|
.AllowAnyHeader()));
|
2023-08-04 00:38:44 +01:00
|
|
|
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
2023-05-26 19:05:44 +01:00
|
|
|
|
2023-08-12 18:35:57 +01:00
|
|
|
builder.WebHost.AddCertificateFromEnvironment();
|
2023-08-10 23:33:15 +01:00
|
|
|
|
2023-08-04 00:38:44 +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();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthorization();
|
2023-08-11 17:16:26 +01:00
|
|
|
app.UseCors("BlogApi");
|
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();
|
2023-08-09 21:08:57 +01:00
|
|
|
app.MapRssFeed("/blog/feed");
|
2023-05-26 19:05:44 +01:00
|
|
|
|
|
|
|
app.Run();
|
2023-08-10 22:49:44 +01:00
|
|
|
|
|
|
|
LogManager.Shutdown();
|