Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

🩺 Updates healthz endpoint usage

Alicia Sykes19bd665d2a67
diff --git a/docs/management.md b/docs/management.md
index 3edf8aed..0dd28b89 100644
--- a/docs/management.md
+++ b/docs/management.md
@@ -105,6 +105,36 @@ docker run -d \
willfarrell/autoheal
```
+### HTTP Healthcheck Endpoint
+
+Dashy also exposes an unauthenticated HTTP liveness endpoint at `/healthz`, which returns a `200` with a small JSON body (`status`, `uptime`, `version`). It bypasses auth and SSL redirection so probes keep working regardless of how Dashy is configured.
+
+Useful when fronting Dashy with a load balancer / reverse proxy that needs an HTTP probe for auto-failover, or when running on Kubernetes:
+
+```yaml
+# Kubernetes
+livenessProbe:
+ httpGet:
+ path: /healthz
+ port: 8080
+```
+
+```yaml
+# Traefik (label on the Dashy service)
+- "traefik.http.services.dashy.loadbalancer.healthcheck.path=/healthz"
+- "traefik.http.services.dashy.loadbalancer.healthcheck.interval=30s"
+```
+
+```caddyfile
+# Caddy (reverse_proxy block)
+reverse_proxy dashy:8080 {
+ health_uri /healthz
+ health_interval 30s
+}
+```
+
+For Nginx Proxy Manager, set the *Forward Hostname* health-check path to `/healthz` under the proxy host's *Custom locations* / advanced config.
+
**[⬆️ Back to Top](#management)**
---
diff --git a/services/app.js b/services/app.js
index e12c046c..dd2b1023 100644
--- a/services/app.js
+++ b/services/app.js
@@ -33,6 +33,7 @@ const getUser = require('./get-user'); // Enables server side user lookup
/* Service endpoint URL paths (see also serviceEndpoints in src/utils/config/defaults.js) */
const ENDPOINTS = {
+ health: '/healthz',
statusPing: '/status-ping',
statusCheck: '/status-check',
save: '/config-manager/save',
@@ -41,6 +42,11 @@ const ENDPOINTS = {
getUser: '/get-user',
};
+/* Read package version once at startup, so healthcheck never touches the disk per-request */
+let appVersion = 'unknown';
+try { appVersion = require(path.join(rootDir, 'package.json')).version || 'unknown'; }
+catch { /* non-fatal β€” fall back to 'unknown' */ }
+
/* Indicates for the webpack config, that running as a server */
process.env.IS_SERVER = 'True';
@@ -173,6 +179,13 @@ function requireAdmin(req, res, next) {
const method = (m, mw) => (req, res, next) => (req.method === m ? mw(req, res, next) : next());
const app = express()
+ .get(ENDPOINTS.health, (req, res) => {
+ res.set('Cache-Control', 'no-store').status(200).json({
+ status: 'ok',
+ uptime: Math.round(process.uptime()),
+ version: appVersion,
+ });
+ })
// Load SSL redirection middleware
.use(sslServer.middleware)
// Load middlewares for parsing JSON, and supporting HTML5 history routing
diff --git a/services/healthcheck.js b/services/healthcheck.js
index 86a3b75d..40481162 100644
--- a/services/healthcheck.js
+++ b/services/healthcheck.js
@@ -14,7 +14,6 @@ const httpsCerts = {
/* Check if either if simular conditions exist that would of had ssl-server.js to enable ssl */
const isSsl = !!fs.existsSync(httpsCerts.private) && !!fs.existsSync(httpsCerts.public);
-// eslint-disable-next-line import/no-dynamic-require
const http = require(isSsl ? 'https' : 'http');
/* Location of the server to test */
@@ -33,7 +32,7 @@ const agent = new http.Agent({
});
const requestOptions = {
- host, port, timeout, agent,
+ host, port, timeout, agent, path: '/healthz',
};
const startTime = new Date(); // Initialize timestamp to calculate time taken
diff --git a/tests/server/general.test.js b/tests/server/general.test.js
index a5167b42..56f82e93 100644
--- a/tests/server/general.test.js
+++ b/tests/server/general.test.js
@@ -4,6 +4,25 @@ import request from 'supertest';
const app = require('../../services/app');
+describe('Healthcheck', () => {
+ it('GET /healthz returns 200 with status, uptime and version', async () => {
+ const res = await request(app).get('/healthz');
+ expect(res.status).toBe(200);
+ expect(res.headers['cache-control']).toBe('no-store');
+ const body = JSON.parse(res.text);
+ expect(body.status).toBe('ok');
+ expect(typeof body.uptime).toBe('number');
+ expect(body.uptime).toBeGreaterThanOrEqual(0);
+ expect(typeof body.version).toBe('string');
+ });
+
+ it('ignores POST', async () => {
+ const res = await request(app).post('/healthz');
+ expect(res.status).toBeLessThan(500);
+ expect(res.status).not.toBe(200);
+ });
+});
+
describe('Config serving', () => {
it('GET /conf.yml returns the config', async () => {
const res = await request(app).get('/conf.yml');