Configuration
health()
Signature
Section titled “Signature”health() — returns struct
Available in: mapper
Category: Routing
Description
Section titled “Description”Register a health check route at /health (or a custom path). Returns a JSON response with status and timestamp by default, or delegates to a custom controller action.
This is useful for container orchestration (Kubernetes liveness/readiness probes), load balancer health checks, and monitoring tools.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
to | string | no | wheels#health | Set controller##action combination for a custom health check handler. If not provided, a default handler returns {"status":"ok","timestamp":"..."}. |
path | string | no | health | Override the URL path. Defaults to "health". |
name | string | no | health | Override the route name. Defaults to "health". |
Examples
Section titled “Examples”<cfscript>
mapper()
// 1. Register the default health check route at /health.
// Responds with {"status":"ok","timestamp":"..."} — no controller needed.
.health()
.root(to="home##index")
.wildcard()
.end();
// 2. Override the URL path and route name.
// Accessible at /healthz instead of /health.
mapper()
.health(path="healthz", name="healthz")
.root(to="home##index")
.end();
// 3. Delegate to a custom controller action for advanced health checks
// (e.g. database ping, cache connectivity).
mapper()
.health(to="system##health")
.root(to="home##index")
.end();
</cfscript>