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
This commit is contained in:
Lucas Berger
2026-06-09 21:13:58 -04:00
parent bf8f63b47c
commit d816f79271
+8 -1
View File
@@ -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.')
}