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:
@@ -115,7 +115,14 @@ if (isMainModule()) {
|
|||||||
const vapidPublicKey = process.env.VAPID_PUBLIC_KEY ?? ''
|
const vapidPublicKey = process.env.VAPID_PUBLIC_KEY ?? ''
|
||||||
const vapidPrivateKey = process.env.VAPID_PRIVATE_KEY ?? ''
|
const vapidPrivateKey = process.env.VAPID_PRIVATE_KEY ?? ''
|
||||||
if (vapidSubject && vapidPublicKey && vapidPrivateKey) {
|
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 {
|
} else {
|
||||||
console.warn('[startup] VAPID env vars not set — push notifications will fail. Set VAPID_SUBJECT, VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY.')
|
console.warn('[startup] VAPID env vars not set — push notifications will fail. Set VAPID_SUBJECT, VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY.')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user