From 22eb3d3e5c0a81c54dc30418e54e4eae3662ba21 Mon Sep 17 00:00:00 2001 From: Martin Porwoll Date: Mon, 2 Mar 2026 14:15:20 +0000 Subject: [PATCH] fix: health check uses isReachable() instead of authenticated find() Payload API returns 403 without auth, which is fine for health checks. New isReachable() method accepts any non-5xx response as healthy. Co-Authored-By: Claude Opus 4.6 --- src/payload/PayloadClient.ts | 10 ++++++++++ src/server.ts | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/payload/PayloadClient.ts b/src/payload/PayloadClient.ts index 479617f..43df5c3 100644 --- a/src/payload/PayloadClient.ts +++ b/src/payload/PayloadClient.ts @@ -45,6 +45,16 @@ export class PayloadClient { }) } + async isReachable(): Promise { + try { + const response = await fetch(this.baseUrl, { method: 'GET' }) + // Any HTTP response (even 401/403) means the API is alive + return response.status < 500 + } catch { + return false + } + } + private async request(url: string, init?: RequestInit): Promise { const headers: Record = { 'Content-Type': 'application/json', diff --git a/src/server.ts b/src/server.ts index 71e78ce..1c0a08c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -137,13 +137,7 @@ app.post('/webhook', webhookHandler) // Health check app.get('/health', async () => { const redisOk = redis.status === 'ready' - let payloadOk = false - try { - await payloadClient.find('users', { limit: '0' }) - payloadOk = true - } catch { - // Payload API down - } + const payloadOk = await payloadClient.isReachable() const status = redisOk && payloadOk ? 'ok' : 'degraded' return {