v1.0.0
This commit is contained in:
1 parent
070168639d
commit
b05cbe61e8
23 files changed
+983
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using HA_Shopping_List.Server.Components;
|
||||
using HA_Shopping_List.Server.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Blazor Server interactif
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents(options => options.DetailedErrors = true);
|
||||
|
||||
// Persistance dans /data (Home Assistant) ou dans le dossier local en Dev
|
||||
var dbFolder = Directory.Exists("/data") ? "/data" : AppContext.BaseDirectory;
|
||||
Directory.CreateDirectory(dbFolder);
|
||||
var dbPath = Path.Combine(dbFolder, "shopping.db");
|
||||
|
||||
builder.Services.AddDbContextFactory<AppDbContext>(options =>
|
||||
options.UseSqlite($"Data Source={dbPath}"));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Création automatique de la base SQLite au démarrage
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var factory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<AppDbContext>>();
|
||||
using var db = factory.CreateDbContext();
|
||||
db.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
context.Response.Headers.Append("Permissions-Policy", "unload=(self)");
|
||||
await next();
|
||||
});
|
||||
#endif
|
||||
|
||||
// Gestion du préfixe dynamique Ingress de Home Assistant
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
if (context.Request.Headers.TryGetValue("X-Ingress-Path", out var ingressPath))
|
||||
{
|
||||
context.Request.PathBase = ingressPath.ToString();
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseAntiforgery();
|
||||
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
|
||||
// Port Ingress standard
|
||||
app.Run("http://0.0.0.0:8099");
|
||||
Reference in new issue
Block a user