From 0e3cb761c969e11e97615ca9404d95314f026185 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:25:03 -0400 Subject: [PATCH] Configure local development environment - Generalize appsettings.json by removing hardcoded credentials - Add local connection string and JWT config to appsettings.Development.json - Add EF Core Design package for running migrations locally - Seed admin user on startup in development - Skip HTTPS redirect in development for proxy compatibility - Gitignore appsettings.Development.json --- .gitignore | 2 ++ .../Api.SeaHavenIndustries.csproj | 4 +++ Api.SeaHavenIndustries/Program.cs | 31 ++++++++++++++++++- .../appsettings.Development.json | 11 +++++++ Api.SeaHavenIndustries/appsettings.json | 12 ++----- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 9f20ab7..9d755ed 100644 --- a/.gitignore +++ b/.gitignore @@ -362,3 +362,5 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd /SeaHavenIndustries/wwwroot/ChromeEx/Win_x64_1000083_chrome-win/chrome-win + +appsettings.Development.json diff --git a/Api.SeaHavenIndustries/Api.SeaHavenIndustries.csproj b/Api.SeaHavenIndustries/Api.SeaHavenIndustries.csproj index 663aadd..99cc48b 100644 --- a/Api.SeaHavenIndustries/Api.SeaHavenIndustries.csproj +++ b/Api.SeaHavenIndustries/Api.SeaHavenIndustries.csproj @@ -8,6 +8,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/Api.SeaHavenIndustries/Program.cs b/Api.SeaHavenIndustries/Program.cs index a97d198..ed827db 100644 --- a/Api.SeaHavenIndustries/Program.cs +++ b/Api.SeaHavenIndustries/Program.cs @@ -93,7 +93,8 @@ if (app.Environment.IsDevelopment() || app.Environment.IsProduction()) }); } -app.UseHttpsRedirection(); +if (!app.Environment.IsDevelopment()) + app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCors(); app.UseAuthentication(); @@ -101,4 +102,32 @@ app.UseAuthorization(); app.MapControllers(); +if (app.Environment.IsDevelopment()) +{ + using var scope = app.Services.CreateScope(); + var userManager = scope.ServiceProvider.GetRequiredService>(); + var roleManager = scope.ServiceProvider.GetRequiredService>(); + + if (!await roleManager.RoleExistsAsync("Admin")) + await roleManager.CreateAsync(new IdentityRole("Admin")); + + var adminEmail = "admin@seahavenind.com"; + if (await userManager.FindByNameAsync(adminEmail) == null) + { + var admin = new ApplicationUser + { + UserName = adminEmail, + Email = adminEmail, + FirstName = "Admin", + LastName = "User", + EmailConfirmed = true, + UniqueName = "Active", + CreatedDate = DateTime.Now + }; + var result = await userManager.CreateAsync(admin, "Admin@123"); + if (result.Succeeded) + await userManager.AddToRoleAsync(admin, "Admin"); + } +} + app.Run(); diff --git a/Api.SeaHavenIndustries/appsettings.Development.json b/Api.SeaHavenIndustries/appsettings.Development.json index 0c208ae..ed07ebd 100644 --- a/Api.SeaHavenIndustries/appsettings.Development.json +++ b/Api.SeaHavenIndustries/appsettings.Development.json @@ -1,8 +1,19 @@ { + "ConnectionStrings": { + "DefaultConnection": "Server=localhost,1433;Database=SeahavenIndustries;User Id=sa;Password=Local@Dev2026!;TrustServerCertificate=True;MultipleActiveResultSets=true" + }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "SendGrid": { + "ApiKey": "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" + }, + "JWT": { + "ValidAudience": "http://localhost:3000", + "ValidIssuer": "https://localhost:7195", + "Secret": "JWTAuthenticationHIGHsecuredPasswordVVVp1OH7Xzyr" } } diff --git a/Api.SeaHavenIndustries/appsettings.json b/Api.SeaHavenIndustries/appsettings.json index afdabec..2247d5d 100644 --- a/Api.SeaHavenIndustries/appsettings.json +++ b/Api.SeaHavenIndustries/appsettings.json @@ -1,12 +1,6 @@ { "ConnectionStrings": { - //"DefaultConnection": "Server=DESKTOP-64LC14O\SQLEXPRESS;Database=SeahavenIndustries;TrustServerCertificate=True;Trusted_Connection=True;MultipleActiveResultSets=true", - - // Test database - //"DefaultConnection": "Server=SQL5112.site4now.net;Initial Catalog=db_a7141e_seahavenindustries;User Id=db_a7141e_seahavenindustries_admin;Password=Abc123!@#;MultipleActiveResultSets=true" - - //Client Database - "DefaultConnection": "Server=SQL5112.site4now.net;Initial Catalog=db_a7141e_seahavenindustry;User Id=db_a7141e_seahavenindustry_admin;Password=Abc123!@#;MultipleActiveResultSets=true" + "DefaultConnection": "" }, "Logging": { "LogLevel": { @@ -15,12 +9,12 @@ } }, "SendGrid": { - "ApiKey": "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" + "ApiKey": "" }, "AllowedHosts": "*", "JWT": { "ValidAudience": "http://localhost:4200", "ValidIssuer": "http://localhost:7195", - "Secret": "JWTAuthenticationHIGHsecuredPasswordVVVp1OH7Xzyr" + "Secret": "" } }