Server now silently fails with no PostgreSQL
This commit is contained in:
@@ -17,6 +17,8 @@ public class NotesController : ControllerBase
|
||||
|
||||
[HttpGet("{cardName}")]
|
||||
public async Task<ActionResult<CardNote>> GetNote(string cardName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var note = await _context.CardNotes.FindAsync(cardName);
|
||||
if (note == null)
|
||||
@@ -25,9 +27,17 @@ public class NotesController : ControllerBase
|
||||
}
|
||||
return Ok(note);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[WARNING] Could not retrieve note from database: {ex.Message}");
|
||||
return Ok(new CardNote { CardName = cardName, Note = "" });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CardNote>> UpdateNote(CardNote note)
|
||||
{
|
||||
try
|
||||
{
|
||||
var existing = await _context.CardNotes.FindAsync(note.CardName);
|
||||
if (existing == null)
|
||||
@@ -40,6 +50,12 @@ public class NotesController : ControllerBase
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[WARNING] Could not save note to database: {ex.Message}");
|
||||
}
|
||||
|
||||
return Ok(note);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,16 +10,31 @@ builder.Services.AddRazorPages();
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
{
|
||||
if (!string.IsNullOrEmpty(connectionString))
|
||||
{
|
||||
options.UseNpgsql(connectionString);
|
||||
}
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Apply migrations
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
if (!string.IsNullOrEmpty(connectionString))
|
||||
{
|
||||
db.Database.Migrate();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[WARNING] Database migration failed: {ex.Message}. The application will continue without a database connection.");
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<OverrideHtmlAssetPlaceholders>false</OverrideHtmlAssetPlaceholders>
|
||||
<StaticWebAssetsFingerprintingEnabled>false</StaticWebAssetsFingerprintingEnabled>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet"/>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet"/>
|
||||
<link href="/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<link href="/_content/Telerik.UI.for.Blazor/css/kendo-theme-default/all.css" rel="stylesheet"/>
|
||||
<link href="/_content/Telerik.UI.for.Blazor/css/kendo-theme-bootstrap/all.css" rel="stylesheet"/>
|
||||
<link href="/css/app.css" rel="stylesheet"/>
|
||||
<link href="/Web.styles.css" rel="stylesheet"/>
|
||||
<script src="/_content/Telerik.UI.for.Blazor/js/telerik-blazor.js" defer></script>
|
||||
|
||||
Reference in New Issue
Block a user