Production Guides & Recipes
Dual Route Pattern (Liveness & Readiness)
Section titled “Dual Route Pattern (Liveness & Readiness)”In Kubernetes and container platforms, configure two separate route handlers:
import { health } from "@/lib/health";import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next";
export const { GET } = createNextHealthRoute(health, { scope: "liveness",});import { health } from "@/lib/health";import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next";
export const { GET } = createNextHealthRoute(health, { scope: "readiness",});Protecting Diagnostics Endpoints
Section titled “Protecting Diagnostics Endpoints”Detailed diagnostic reports must not be public. Pass protect with a bearer token, basic auth, or an IP allowlist:
import { health } from "@/lib/health";import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next";
const token = process.env.HEALTH_DIAGNOSTICS_TOKEN;if (!token) throw new Error("HEALTH_DIAGNOSTICS_TOKEN is required");
export const { GET, HEAD } = createNextHealthRoute(health, { scope: "diagnostics", includeDetails: true, protect: { bearerToken: token },});The caller sends Authorization: Bearer <token>. A failed check answers 401. The route throws HEALTHCHECK_INVALID_CONFIG at construction when protect is empty, when the token is blank, or when bearerToken and basicAuth are both set.
IP Allowlists Behind Proxies
Section titled “IP Allowlists Behind Proxies”allowIps and allowCidrs are IPv4 only and require trustProxy: true. The client address is read from the right end of the proxy header, because the entries to the left can be forged by the client. trustedProxyHops (integer >= 1, default 1) is the number of proxies you run in front of the app:
export const { GET, HEAD } = createNextHealthRoute(health, { scope: "diagnostics", protect: { trustProxy: true, trustedProxyHops: 2, // CDN -> nginx -> app allowCidrs: ["10.0.0.0/8"], },});If the header has fewer entries than trustedProxyHops, the request is denied. Use proxyHeader to read a header other than x-forwarded-for.
Troubleshooting & Common Pitfalls
Section titled “Troubleshooting & Common Pitfalls”1. Next.js Static Compilation Stale Responses
Section titled “1. Next.js Static Compilation Stale Responses”If Next.js attempts to statically pre-render the route at build time, ensure you export dynamic = 'force-dynamic' or let createNextHealthRoute set dynamic runtime headers automatically:
export const dynamic = "force-dynamic";2. Edge Runtime Incompatibility with Node Checks
Section titled “2. Edge Runtime Incompatibility with Node Checks”If your Next.js route uses export const runtime = 'edge', do not include Node-specific checks (like containerResourceCheck or dnsCheck) in your health manager. Use edge-safe core checks or run the health route on the standard Node runtime.