Update cert config
This commit is contained in:
1 parent
f42b3dc4a1
commit
65a71c5b5f
2 files changed
+37
-27
No files matched your search
+33
-11
@@ -9,6 +9,28 @@ using BudgetApp.Data.Interfaces;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Host.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.ConfigureKestrel(options =>
|
||||
{
|
||||
options.ConfigureHttpsDefaults(adapterOptions =>
|
||||
{
|
||||
var pemCertFile = "app/data/certs/cert.pem";
|
||||
var pemKeyFile = "app/data/certs/key.pem";
|
||||
|
||||
if (File.Exists(pemCertFile) && File.Exists(pemKeyFile))
|
||||
{
|
||||
adapterOptions.ServerCertificate = System.Security.Cryptography.X509Certificates.X509Certificate2.CreateFromPemFile(pemCertFile, pemKeyFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No certificate found — fallback to default development certificate
|
||||
adapterOptions.ServerCertificate = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Database
|
||||
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseSqlite(
|
||||
@@ -82,17 +104,16 @@ builder.Services.AddScoped<AppState>();
|
||||
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
|
||||
// HSTS
|
||||
//if (bool.Parse(Environment.GetEnvironmentVariable("ENABLE_HSTS") ?? "false"))
|
||||
//{
|
||||
// builder.Services.AddHsts(options =>
|
||||
// {
|
||||
// var hstsSection = builder.Configuration.GetSection("Hsts");
|
||||
// options.MaxAge = TimeSpan.FromDays(hstsSection.GetValue<int>("MaxAgeDays", 365));
|
||||
// options.IncludeSubDomains = hstsSection.GetValue<bool>("IncludeSubDomains", true);
|
||||
// options.Preload = hstsSection.GetValue<bool>("Preload", false);
|
||||
// });
|
||||
//}
|
||||
if (bool.Parse(Environment.GetEnvironmentVariable("ENABLE_HSTS") ?? "false"))
|
||||
{
|
||||
builder.Services.AddHsts(options =>
|
||||
{
|
||||
var hstsSection = builder.Configuration.GetSection("Hsts");
|
||||
options.MaxAge = TimeSpan.FromDays(hstsSection.GetValue<int>("MaxAgeDays", 365));
|
||||
options.IncludeSubDomains = hstsSection.GetValue<bool>("IncludeSubDomains", true);
|
||||
options.Preload = hstsSection.GetValue<bool>("Preload", false);
|
||||
});
|
||||
}
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents()
|
||||
@@ -112,6 +133,7 @@ if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||
// 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.UseStatusCodePagesWithReExecute("/not-found");
|
||||
|
||||
Reference in new issue
Block a user