f2d6300d72
deploy / deploy (push) Failing after 13s
.gitignore has '/data' which Windows git (case-insensitive) silently matched '/Data/', so AppDbContext.cs was never committed and the Docker build (Linux, case-sensitive) failed with CS0234 'Data' not found. Renaming the directory to 'Database/' sidesteps the collision. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SoroushAsadi.Database;
|
|
using SoroushAsadi.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// --- Razor Pages ---
|
|
builder.Services.AddRazorPages();
|
|
|
|
// --- Authentication (single-password cookie auth) ---
|
|
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
.AddCookie(opt =>
|
|
{
|
|
opt.LoginPath = "/Admin/Login";
|
|
opt.LogoutPath = "/Admin/Logout";
|
|
opt.Cookie.Name = "sa_admin";
|
|
opt.Cookie.HttpOnly = true;
|
|
opt.Cookie.SameSite = SameSiteMode.Lax;
|
|
opt.ExpireTimeSpan = TimeSpan.FromDays(7);
|
|
opt.SlidingExpiration = true;
|
|
});
|
|
builder.Services.AddAuthorization();
|
|
|
|
// --- EF Core + SQLite ---
|
|
var dataDir = builder.Configuration["DataDir"]
|
|
?? Path.Combine(builder.Environment.ContentRootPath, "data");
|
|
Directory.CreateDirectory(dataDir);
|
|
Directory.CreateDirectory(Path.Combine(dataDir, "uploads"));
|
|
|
|
builder.Services.AddDbContext<AppDbContext>(opt =>
|
|
opt.UseSqlite($"Data Source={Path.Combine(dataDir, "cms.db")}"));
|
|
|
|
// --- App services ---
|
|
builder.Services.AddScoped<ContentService>();
|
|
builder.Services.AddScoped<AuthService>();
|
|
builder.Services.AddScoped<EmailService>();
|
|
builder.Services.AddHttpClient<EmailService>();
|
|
|
|
// --- Static file serving for /data/uploads ---
|
|
builder.Services.Configure<StaticFileOptions>(opt => { });
|
|
|
|
var app = builder.Build();
|
|
|
|
// Run EF migrations on startup (creates DB if missing)
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
|
db.Database.EnsureCreated();
|
|
}
|
|
|
|
app.UseStatusCodePagesWithReExecute("/Error/{0}");
|
|
app.UseStaticFiles();
|
|
|
|
// Serve uploaded files from /data/uploads under /uploads/*
|
|
var uploadsPath = Path.Combine(dataDir, "uploads");
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(uploadsPath),
|
|
RequestPath = "/uploads"
|
|
});
|
|
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.MapRazorPages();
|
|
|
|
app.Run();
|