function publicHost() { return String(process.env.WEBHOOK_HOST || process.env.SPACE_HOST || process.env.PORTAL_HOST || '') .replace(/^https?:\/\//, '') .replace(/\/+$/, ''); } function snippeWebhookUrl(path = '/api/webhooks/snippe') { const host = publicHost(); if (!host) { throw new Error('WEBHOOK_HOST, SPACE_HOST, or PORTAL_HOST is required for Snippe webhooks'); } const normalizedPath = path.startsWith('/') ? path : `/${path}`; return `https://${host}${normalizedPath}`; } module.exports = { snippeWebhookUrl };