diff --git a/.gitignore b/.gitignore index 9491a2f..664d14a 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,7 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# Setupfil för Aberwyn +infrastructure/setup.json diff --git a/Aberwyn/Infrastructure/setup.json b/Aberwyn/Infrastructure/setup.json deleted file mode 100644 index f9402c6..0000000 --- a/Aberwyn/Infrastructure/setup.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "AdminUsername": "tai", - "AdminEmail": "tai@zcz.se", - "AdminPassword": "Admin123!", - "IsConfigured": true, - "DbHost": "localhost", - "DbPort": 3306, - "DbName": "aberwyn_test", - "DbUser": "root", - "DbPassword": "rootpass" -} \ No newline at end of file diff --git a/Aberwyn/Program.cs b/Aberwyn/Program.cs index edcccf6..3c22930 100644 --- a/Aberwyn/Program.cs +++ b/Aberwyn/Program.cs @@ -22,14 +22,26 @@ var builder = WebApplication.CreateBuilder(new WebApplicationOptions }); builder.Configuration.AddConfiguration(config); -// Läser setup.json + +// Läser setup.json eller skapar en ny tom om den inte finns var setupFilePath = Path.Combine("infrastructure", "setup.json"); + +if (!File.Exists(setupFilePath)) +{ + var initialSettings = new SetupSettings + { + IsConfigured = false, + DbPort = 3306 + }; + + var initialJson = JsonSerializer.Serialize(initialSettings, new JsonSerializerOptions { WriteIndented = true }); + Directory.CreateDirectory(Path.GetDirectoryName(setupFilePath)!); // säkerställ att mappen finns + File.WriteAllText(setupFilePath, initialJson); +} + SetupSettings setup; try { - if (!File.Exists(setupFilePath)) - throw new Exception("setup.json saknas."); - using var jsonStream = File.OpenRead(setupFilePath); setup = JsonSerializer.Deserialize(jsonStream)!; @@ -51,6 +63,7 @@ catch (Exception ex) } + // Add services to the container builder.Services.AddControllersWithViews() .AddJsonOptions(opts =>