peppa/apps/web/app/api/health/route.ts
peppa-bot ce03df667c
Some checks failed
peppa/lint lint: success за 3с
peppa/typecheck typecheck: success за 55с
peppa/build build: success за 35с
peppa/test test: failure за 1720с
peppa-ci / ci (pull_request) Failing after 31m5s
PEP-272: /api/health анониму — только ok; без X-Powered-By, script-src в CSP, аватар по https
- /api/health без ключа X-Peppa-Health (HMAC от PEPPA_SECRET, принимается и PREVIOUS) отдаёт только {ok};
  ключ шлют сторож адреса, сторож отставания выкатки, healthcheck контейнеров, скрипты выкатки
- poweredByHeader: false; CSP: script-src 'self' 'unsafe-inline' (unsafe-eval только в dev), worker-src 'self'
- httpsAvatar: http → https при записи и показе
- тест health-anon.test.ts, change archived

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 20:36:06 +00:00

21 lines
950 B
TypeScript

import { HEALTH_HEADER, healthBody, healthReport } from "@peppa/core";
import { bootId } from "@/lib/boot";
import { db } from "@/lib/db";
export const dynamic = "force-dynamic";
/**
* Health check (PEP-20): DB, version, service heartbeats. 503 if the DB is down.
* PEP-272: without the internal key (`X-Peppa-Health`) only `{ok}` — no version, commit or services
* for strangers. Deploy scripts, container healthchecks and the watchdog send the key.
*/
export async function GET(req: Request) {
const r = await healthReport(db, {
version: process.env.NEXT_PUBLIC_PEPPA_VERSION,
commit: process.env.NEXT_PUBLIC_PEPPA_COMMIT || null,
});
// PEP-114: `boot` changes when the web process restarts — the domain guard recognises FORGE by it.
const body = healthBody({ ...r, boot: bootId() }, req.headers.get(HEALTH_HEADER));
return Response.json(body, { status: r.ok ? 200 : 503, headers: { "Cache-Control": "no-store" } });
}