- /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>
21 lines
950 B
TypeScript
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" } });
|
|
}
|