-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
130 lines (109 loc) · 4.49 KB
/
Program.cs
File metadata and controls
130 lines (109 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using QuillKit.Services;
using QuillKit.Extensions;
using QuillKit.Models;
using Microsoft.AspNetCore.Mvc.Razor;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
// Add session support for admin authentication
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.IdleTimeout = TimeSpan.FromHours(2);
});
// 🔄 Parse content provider configuration once
var contentProviderString = builder.Configuration.GetValue<string>("ContentProvider", "Local");
var contentProvider = contentProviderString.ToLowerInvariant() switch
{
"azureblob" or "azure" => ContentProvider.AzureBlob,
"local" or "file" or _ => ContentProvider.Local
};
Console.WriteLine($"🔧 Content Provider: {contentProviderString} -> {contentProvider}");
// 🎨 Configure theme view location expansion
builder.Services.Configure<RazorViewEngineOptions>(options =>
{
// Note: We'll configure the view location expander after services are built
// to avoid BuildServiceProvider issues
});
// Theme views are always served locally for performance
// Configure services during build phase
switch (contentProvider)
{
case ContentProvider.AzureBlob:
builder.Services.AddSingleton<IContentService, AzureBlobContentService>();
builder.Services.AddSingleton<IPostService, FilePostService>();
break;
case ContentProvider.Local:
default:
builder.Services.AddSingleton<IContentService, LocalFileContentService>();
builder.Services.AddSingleton<IPostService, FilePostService>();
break;
}
// Register our other services
builder.Services.AddSingleton<PostParser>();
builder.Services.AddSingleton<SiteConfigService>();
builder.Services.AddSingleton<SyndicationService>();
builder.Services.AddSingleton<SitemapService>();
builder.Services.AddSingleton<RobotsService>();
// 🎨 Configure view location expander now that services are registered
builder.Services.PostConfigure<RazorViewEngineOptions>(options =>
{
// Add our theme expander (don't clear existing ones to preserve default view locations)
options.ViewLocationExpanders.Add(new ThemeViewLocationExpander(builder.Environment));
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Site/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();
// Serve static files from wwwroot (CSS, JS, images, etc.)
app.UseStaticFiles();
app.UseRouting();
// Enable session middleware so HttpContext.Session is available
app.UseSession();
app.UseAuthorization();
// Configure static file serving based on content provider
switch (contentProvider)
{
case ContentProvider.AzureBlob:
// 🌐 Add Azure Blob static file middleware for /media and /assets
app.UseMiddleware<AzureBlobStaticFileMiddleware>();
break;
case ContentProvider.Local:
default:
// Serve static files from Content/media folder at /media URL
var mediaPath = Path.Combine(builder.Environment.ContentRootPath, "Content", "media");
if (Directory.Exists(mediaPath))
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
Path.Combine(builder.Environment.ContentRootPath, "Content", "media")),
RequestPath = "/media"
});
}
// Serve static files from Content/theme/assets folder at /assets URL
var assetPath = Path.Combine(builder.Environment.ContentRootPath, "Content", "Theme", "assets");
if (Directory.Exists(assetPath))
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
Path.Combine(builder.Environment.ContentRootPath, "Content", "Theme", "assets")),
RequestPath = "/assets"
});
}
break;
}
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Site}/{action=Index}/{id?}")
.WithStaticAssets();
app.Run();