# healthcheck-next — Agent usage Configure a coding agent for @nexload-sdk/healthcheck-next. **Topic:** agents **Package:** `@nexload-sdk/healthcheck-next` v3.1.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/next/agents/ ## Install matching skills Install the skills whose triggers match the task. ### healthcheck-nextjs-routes [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/nextjs-routes/SKILL.md) ```text Use when wiring @nexload-sdk/healthcheck-next into Next.js App Router liveness, readiness, startup, diagnostics, or metrics route modules, including a server-only manager singleton, GET/HEAD behavior, scope and status policy, no-store route constants, response formats, and fail-closed route protection. Do not use for non-Next servers. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-nextjs-routes ``` ### healthcheck-diagnostics-security [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/diagnostics-security/SKILL.md) ```text Use when deciding or reviewing public versus private health exposure, diagnostics details, metrics access, JSON redaction, error and stack suppression, bearer or Basic authentication, IPv4/CIDR allowlists, trusted proxy headers, no-store policy, or sensitive and high-cardinality health data. Compose with the route or exporter skill that owns implementation. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-diagnostics-security ``` ## Project AGENTS.md ```markdown For @nexload-sdk/healthcheck-next, load healthcheck-nextjs-routes when its trigger matches. Read the package bundle and check public exports against the installed version before editing. ``` ## Package context [Scoped Markdown bundle](/nexload-sdk/packages/healthcheck/next/llms.txt). ## Prompts ```text Expose health routes in Next.js. Use @nexload-sdk/healthcheck-next and healthcheck-nextjs-routes. Inspect the installed version and show a minimal typed example for my project. ``` ```text Review my @nexload-sdk/healthcheck-next integration against the optimization page. Identify the relevant source for each finding and one test for the highest-risk behavior. ``` --- # API Reference & Compatibility Public API symbol reference and compatibility matrix for Healthcheck Next.js. **Topic:** api **Package:** `@nexload-sdk/healthcheck-next` v3.1.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/next/api/ The complete public API symbol inventory is generated automatically from package source exports: ## Functions ### `createNextHealthRoute` ```ts createNextHealthRoute(manager: HealthManager, options: NextHealthRouteOptions) => { GET: (request: Request) => Promise; HEAD: (request: Request) => Promise; } ``` **Exported from:** `@nexload-sdk/healthcheck-next` Public function exported by @nexload-sdk/healthcheck-next. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/src/index.ts#L301) ### `createNextMetricsRoute` ```ts createNextMetricsRoute(manager: HealthManager, options: NextMetricsRouteOptions) => { GET: (request: Request) => Promise; } ``` **Exported from:** `@nexload-sdk/healthcheck-next` Public function exported by @nexload-sdk/healthcheck-next. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/src/index.ts#L355) ## Interfaces ### `NextHealthRouteOptions` ```ts interface NextHealthRouteOptions { scope: HealthScope format?: "json" | "summary" httpStatus?: HealthHttpStatusPolicy includeDetails?: boolean | ((request: Request) => boolean) protect?: NextHealthRouteProtection headers?: HeadersInit | ((report: HealthReport) => HeadersInit) cache?: "no-store" } ``` **Exported from:** `@nexload-sdk/healthcheck-next` Public interface exported by @nexload-sdk/healthcheck-next. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/src/index.ts#L33) ### `NextHealthRouteProtection` ```ts interface NextHealthRouteProtection { bearerToken?: string basicAuth?: { username: string password: string } allowCidrs?: readonly string[] allowIps?: readonly string[] trustProxy?: boolean proxyHeader?: "x-forwarded-for" | "x-real-ip" | string trustedProxyHops?: number } ``` **Exported from:** `@nexload-sdk/healthcheck-next` Public interface exported by @nexload-sdk/healthcheck-next. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/src/index.ts#L20) ### `NextMetricsRouteOptions` ```ts interface NextMetricsRouteOptions { format: "prometheus" | "openmetrics" | "json" scope?: HealthRunScope protect?: NextHealthRouteProtection prefix?: string defaultLabels?: Record } ``` **Exported from:** `@nexload-sdk/healthcheck-next` Public interface exported by @nexload-sdk/healthcheck-next. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/src/index.ts#L43) *** ## Runtime Compatibility Matrix | Runtime / Engine | Version Requirement | Verification Status | |---|---|---| | **Next.js** | `>=14.0.0` | Verified on Next.js 14 & 15 App Router | | **Node.js** | `>=20.9.0` | Node.js Route Handler runtime | | **Module Format** | ESM only | Native ECMAScript Modules | | **Side Effects** | `false` | Fully tree-shakeable | --- # Production Guides & Recipes Setting up liveness, readiness, and protected diagnostics routes in Next.js App Router. **Topic:** guides **Package:** `@nexload-sdk/healthcheck-next` v3.1.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/next/guides/ ## Dual Route Pattern (Liveness & Readiness) In Kubernetes and container platforms, configure two separate route handlers: ```ts // app/api/health/live/route.ts import { health } from "@/lib/health"; import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next"; export const { GET } = createNextHealthRoute(health, { scope: "liveness", }); ``` ```ts // app/api/health/ready/route.ts import { health } from "@/lib/health"; import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next"; export const { GET } = createNextHealthRoute(health, { scope: "readiness", }); ``` *** ## Protecting Diagnostics Endpoints Detailed diagnostic reports must not be public. Pass `protect` with a bearer token, basic auth, or an IP allowlist: ```ts // app/api/health/diagnostics/route.ts 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 `. 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 `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: ```ts 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 ### 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: ```ts export const dynamic = "force-dynamic"; ``` ### 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. --- # Overview & Quick Start Production-ready no-store, zero-cache health and readiness route handlers for Next.js App Router. **Topic:** overview **Package:** `@nexload-sdk/healthcheck-next` v3.1.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/next/ **Package:** `@nexload-sdk/healthcheck-next` **Workspace version:** `3.1.0` Next.js App Router route factories for @nexload-sdk/healthcheck. [npm](https://www.npmjs.com/package/@nexload-sdk/healthcheck-next) · [Source](https://github.com/gecut/nexload-sdk/tree/main/packages/healthcheck/next) `@nexload-sdk/healthcheck-next` binds `@nexload-sdk/healthcheck` to Next.js App Router Route Handlers. It automatically enforces `Cache-Control: no-store` headers, prevents static optimization of health endpoints, maps status codes to Kubernetes expectations, and provides token-based proxy protection. *** ## 10-Second Code Snippet ```ts // app/api/health/route.ts import { createHealthManager } from "@nexload-sdk/healthcheck"; import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next"; const health = createHealthManager({ service: { name: "web-storefront" }, }); export const { GET } = createNextHealthRoute(health, { scope: "readiness", }); ``` *** ## What You Get * **Next.js App Router Handlers**: Export `GET` and `HEAD` handlers compliant with Next.js 14, 15, and canary. * **Zero-Cache Guarantees**: Forces `force-dynamic` behavior with `Cache-Control: no-store, no-cache, must-revalidate` to prevent CDN and browser caching. * **HTTP Status Code Mapping**: Returns `200 OK` for `"ok"` and `"degraded"`, and `503 Service Unavailable` for `"unhealthy"`. * **Diagnostics Authorization**: Protect operational details behind Bearer tokens or secret headers when exposing internal metrics. *** ## Installation & Requirements ```bash pnpm add @nexload-sdk/healthcheck-next @nexload-sdk/healthcheck next ``` With alternative package managers: ```bash # npm npm install @nexload-sdk/healthcheck-next @nexload-sdk/healthcheck next # bun bun add @nexload-sdk/healthcheck-next @nexload-sdk/healthcheck next ``` Requires Next.js `>=14.0.0` and Node.js `>=20.9.0`. *** ## Next Steps * Explore [Production Guides & Route Recipes](./guides/) for liveness vs readiness routes, proxy authorization, and troubleshooting. * Check the [API Reference & Signatures](./api/) for all exported route creators and options. ## Next steps [Optimization](./optimization/) [Agent usage](./agents/) --- # healthcheck-next — Optimization Production choices for @nexload-sdk/healthcheck-next. **Topic:** optimization **Package:** `@nexload-sdk/healthcheck-next` v3.1.0 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/next/optimization/ ## Trust a controlled proxy IP and CIDR filtering support IPv4 and require trustProxy. Enable it only when the reverse proxy strips and sets the configured header. ## Choose one authorization scheme Select bearer token or basic authentication per route. Both use the Authorization header. ## Keep responses uncached Responses use `cache-control: no-store, max-age=0`. Health route `includeDetails` defaults to `false`; enable details only for protected routes. ## Match the runtime to the manager The route adapter supports Next.js Node.js and Edge runtimes. Use `runtime = "nodejs"` when the manager uses the Node adapter. ## Sources [Package guidance](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/README.md) · [Implementation](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/next/src/index.ts). · [Matching skill](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/nextjs-routes/SKILL.md).