Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add healthcheck webapi endpoint (#49)

Leendert de Borst66b33a8686b3
diff --git a/.github/workflows/docker-compose-build.yml b/.github/workflows/docker-compose-build.yml
index c36a856b2..293734760 100644
--- a/.github/workflows/docker-compose-build.yml
+++ b/.github/workflows/docker-compose-build.yml
@@ -41,8 +41,8 @@ jobs:
run: |
# Test if the service on localhost:81 responds
http_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:81)
- if [ "$http_code" -ne 200 ] && [ "$http_code" -ne 404 ]; then
- echo "Service did not respond with expected 200 OK or 404 Not Found"
+ if [ "$http_code" -ne 200 ] then
+ echo "Service did not respond with expected 200 OK. Check if all DB migrations are applied."
exit 1
else
echo "Service responded with $http_code"
diff --git a/src/AliasVault.Api/Controllers/IdentityController.cs b/src/AliasVault.Api/Controllers/IdentityController.cs
index da11de04c..c0bfea5c9 100644
--- a/src/AliasVault.Api/Controllers/IdentityController.cs
+++ b/src/AliasVault.Api/Controllers/IdentityController.cs
@@ -8,7 +8,6 @@
namespace AliasVault.Api.Controllers;
using AliasDb;
-using AliasGenerators.Identity;
using AliasGenerators.Identity.Implementations;
using Asp.Versioning;
using Microsoft.AspNetCore.Identity;
diff --git a/src/AliasVault.Api/Controllers/RootController.cs b/src/AliasVault.Api/Controllers/RootController.cs
new file mode 100644
index 000000000..ab13a5c47
--- /dev/null
+++ b/src/AliasVault.Api/Controllers/RootController.cs
@@ -0,0 +1,52 @@
+//-----------------------------------------------------------------------
+// <copyright file="RootController.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Controllers;
+
+using AliasDb;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+
+/// <summary>
+/// Root controller that contains health check endpoints.
+/// </summary>
+[ApiController]
+[Route("/")]
+public class RootController : ControllerBase
+{
+ /// <summary>
+ /// Root endpoint that returns a 200 OK if the database connection is successful
+ /// and the DB migrations are up-to-date.
+ /// </summary>
+ /// <returns>Http 200 if database connection is successful.</returns>
+ [HttpGet]
+ public IActionResult Get()
+ {
+ try
+ {
+ using (var dbContext = new AliasDbContext())
+ {
+ var appliedMigrations = dbContext.Database.GetAppliedMigrations();
+ var allMigrations = dbContext.Database.GetMigrations();
+
+ if (allMigrations.Except(appliedMigrations).Any())
+ {
+ // There are pending migrations
+ return StatusCode(500, "Internal server error");
+
+ }
+
+ // Database is up to date
+ return Ok("OK");
+ }
+ }
+ catch
+ {
+ return StatusCode(500, "Internal server error");
+ }
+ }
+}