Every production app needs a health endpoint. Load balancers, Kubernetes, and monitoring systems all need to know if your app is alive.
Alepha provides health endpoints out of the box.
1import { Alepha } from "alepha";2import { AlephaServerHealth } from "alepha/server-health";3 4const alepha = Alepha.create()5 .with(AlephaServerHealth);
This gives you two endpoints:
/health - Detailed HealthReturns JSON with status and uptime:
1{2 "status": "ok",3 "uptime": 123454}
Use this for monitoring dashboards and detailed checks.
/healthz - Simple ProbeReturns plain text:
ok
Use this for Kubernetes liveness/readiness probes. It's lightweight and fast.
1apiVersion: v1 2kind: Pod 3spec: 4 containers: 5 - name: app 6 livenessProbe: 7 httpGet: 8 path: /healthz 9 port: 300010 initialDelaySeconds: 511 periodSeconds: 1012 readinessProbe:13 httpGet:14 path: /healthz15 port: 300016 initialDelaySeconds: 517 periodSeconds: 5
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 CMD curl -f http://localhost:3000/healthz || exit 1
Most load balancers (AWS ALB, nginx, HAProxy) can use /healthz to check if instances are healthy:
AWS ALB:
Health check path: /healthz
Healthy threshold: 2
Unhealthy threshold: 3
Timeout: 5 seconds
Interval: 30 seconds
nginx:
upstream backend {
server app1:3000;
server app2:3000;
health_check uri=/healthz interval=10s;
}
Need to check database connectivity or external services? Extend the health check:
1import { $action } from "alepha/server"; 2import { $inject } from "alepha"; 3import { DatabaseService } from "./DatabaseService"; 4 5class CustomHealthApi { 6 db = $inject(DatabaseService); 7 8 health = $action({ 9 method: "GET",10 path: "/health",11 handler: async () => {12 const dbHealthy = await this.db.ping();13 14 return {15 status: dbHealthy ? "ok" : "degraded",16 uptime: process.uptime(),17 checks: {18 database: dbHealthy ? "ok" : "error",19 },20 };21 },22 });23}
/healthz fast - Don't do database queries or external calls/health for deep checks - Include dependency status