feat: native healthcheck lifecycle endpoints (`/healthz`, `/livez`, `/readyz`)

オープン
#4,451 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
kubernetes, node.js, typescript

調査の方向性

まず nitro.config.ts で提案されている healthCheck オプションと、server/plugins/health.ts の登録例を確認し、次に Nitro に既存する plugin および route のライフサイクル API を調査します。server/routes/health.ts の既存パターンと設計を比較します。完了時には、エンドポイント、ライフサイクル、設定、登録、レスポンス契約が確定しており、ドキュメント化されたステータスマトリクスをカバーしている必要があります。

索引モデルが issue の本文から書いたものです。

説明

Describe the feature

Summary

This proposal outlines the addition of standardized, configurable health check endpoints directly into Nitro.

As Nuxt and Nitro applications are often deployed to cloud-native platforms (Kubernetes, AWS ECS, Google Cloud Run, Azure Container Apps, Docker Swarm), there is a need for orchestrators to reliably query application state during startup, steady state, and degraded state.

Currently, Nitro seems to be missing a standard lifecycle state indicator during boot and runtime, leading to deployment challenges like dropped traffic during rolling updates or premature container restarts during slow initialization tasks (e.g., DB migrations, cache priming, or heavy dynamic module loading).

Related issues:

Problem Statement

When deploying Nitro/Nuxt applications in containerized orchestration environments:

  1. Slow Startup Misinterpretation: Orchestrators using simple HTTP ping tests (e.g., GET /) during boot cannot distinguish between a process that is actively initializing versus one that has crashed or deadlocked. If initialization takes 30-60 seconds, orchestrators may repeatedly kill and restart the container before boot completes.
  2. Traffic Routing During Boot: In rolling deployment scenarios, load balancers may route production traffic to a newly spawned container while background server plugins or dynamic module imports are still completing, resulting in user-facing 500 errors.
  3. Inconsistent Developer Implementations: Currently, developers must manually build custom server routes (e.g., server/routes/health.ts), implement global state flags, and manage dependency ping logic themselves. This leads to fragmented, error-prone patterns across different projects.

Proposed Solution: The Lifecycle Health Probe Pattern

Nitro should introduce built-in health endpoints following the Kubernetes Health Endpoint Pattern.

Standard Endpoint Triumvirate

By default, Nitro will expose sub-paths under a configurable base prefix (e.g., /_health or /healthz):

Endpoint Path Probe Type Question Answered Trigger Conditions & Responsibilities
GET /healthz/startup (or /startupz) Startup Probe "Has initialization finished?" Checks if Nitro hooks, server plugins, and startup tasks have resolved.
GET /healthz/liveness (or /livez) Liveness Probe "Is the Node.js loop responsive?" Checks process responsiveness / deadlock detection. Does NOT ping external DBs.
GET /healthz/readiness (or /readyz) Readiness Probe "Can we route user traffic here?" Checks if Nitro is initialized AND critical upstream dependencies (DB, Redis) are reachable.

Lifecycle Behavior & Status Matrix

The table below illustrates status codes and payloads across the complete container lifecycle:

Phase / Scenario /healthz/startup /healthz/liveness /healthz/readiness Action by Orchestrator
Phase A: Booting / Warming Caches 503 Service Unavailable 200 OK 503 Service Unavailable Hold off routing traffic; do NOT restart container.
Phase B: Fully Booted & Ready 200 OK 200 OK 200 OK Route production traffic to container.
Phase C: Upstream Dependency Outage 200 OK 200 OK 503 Service Unavailable Temporarily pull instance out of load balancer; do NOT restart container process.
Phase D: Process Deadlock / Frozen Loop Timeout / 500 Timeout / 500 Timeout / 500 Restart container instance.

API & Configuration Design

Configuration Options (nitro.config.ts)
export default defineNitroConfig({
  healthCheck: {
    enabled: true,
    path: '/healthz', // Base prefix for endpoints
    headers: {
      'Cache-Control': 'no-cache, no-store, must-revalidate'
    },
    // Optional standalone route aliases
    routes: {
      startup: '/healthz/startup',
      liveness: '/healthz/liveness',
      readiness: '/healthz/readiness'
    }
  }
})
Server Plugin Extensions (server/plugins/health.ts)

Developers can register custom health checks directly in Nitro plugins:

export default defineNitroPlugin((nitroApp) => {
  // Register a check that must pass before readiness turns 200 OK
  nitroApp.registerReadinessCheck('database', async () => {
    const { isConnected, latencyMs } = await db.ping();
    if (!isConnected) {
      throw new Error('Database ping failed');
    }
    return { status: 'UP', latencyMs };
  });

  // Register a custom startup task check
  nitroApp.registerStartupCheck('cache-warmup', async () => {
    return await checkCacheStatus();
  });
});

Payload Format Specifications

Startup In-Progress Response (503 Service Unavailable)
{
  "status": "INITIALIZING",
  "timestamp": "2026-07-20T11:25:00.000Z",
  "checks": {
    "nitro:init": "IN_PROGRESS",
    "cache-warmup": "PENDING"
  }
}
Steady-State Ready Response (200 OK)
{
  "status": "UP",
  "timestamp": "2026-07-20T11:26:00.000Z",
  "checks": {
    "nitro:init": "UP",
    "database": "UP",
    "cache-warmup": "UP"
  }
}
Degraded Readiness Response (503 Service Unavailable)
{
  "status": "DOWN",
  "timestamp": "2026-07-20T11:30:00.000Z",
  "checks": {
    "nitro:init": "UP",
    "database": "DOWN (Connection Refused)",
    "cache-warmup": "UP"
  }
}
Additional information
  • Would you be willing to help implement this feature?
主要言語
TypeScript
スター
11.5k
フォーク
968
平均マージ
4日 9時間
マージ済み PR(30日)
64

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nitrojs/nitro のほかの issue

nitrojs/nitro の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。