From d816f792719f7f060b398a1e4274e8b2999dbbac Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Tue, 9 Jun 2026 21:13:58 -0400 Subject: [PATCH] fix(05-04): wrap setVapidDetails in try/catch to prevent startup crash on bad VAPID key - Bad/truncated VAPID_PRIVATE_KEY logs a warning instead of crashing the server - API still starts and serves all other routes; push dispatch fails with a log message --- apps/api/src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 5c8625a..c9e791d 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -115,7 +115,14 @@ if (isMainModule()) { const vapidPublicKey = process.env.VAPID_PUBLIC_KEY ?? '' const vapidPrivateKey = process.env.VAPID_PRIVATE_KEY ?? '' if (vapidSubject && vapidPublicKey && vapidPrivateKey) { - webpush.setVapidDetails(vapidSubject, vapidPublicKey, vapidPrivateKey) + try { + webpush.setVapidDetails(vapidSubject, vapidPublicKey, vapidPrivateKey) + } catch (err) { + console.warn( + '[startup] setVapidDetails failed — push notifications will not work:', + err instanceof Error ? err.message : String(err), + ) + } } else { console.warn('[startup] VAPID env vars not set — push notifications will fail. Set VAPID_SUBJECT, VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY.') }