Wifiv2 / src /utils /webhookUrl.js
Mbonea's picture
Use Space HTTPS URL for Snippe webhooks
657f281
Raw
History Blame Contribute Delete
545 Bytes
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 };