Fix contact and comment webhook delivery - #13
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b5258a8005
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| return url.protocol === 'https:' | ||
| && allowedHosts.has(url.hostname) | ||
| && /^\/api\/webhooks\/\d+\/[A-Za-z0-9_-]+\/?$/.test(url.pathname) |
There was a problem hiding this comment.
Accept versioned Discord webhook paths
Discord's API also accepts webhook endpoints under versioned paths such as /api/v10/webhooks/{id}/{token}. Any existing setting using that valid form previously reached Discord through the unrestricted fetch, but this regex now rejects it before sending, causing contact submissions to return 502 and comment notifications to be dropped. Allow the optional API-version segment while retaining the host and webhook-ID checks.
Useful? React with 👍 / 👎.
| const [webhookResult, emailResult] = await Promise.allSettled([ | ||
| sendDiscordWebhook(webhookUrl, webhookPayload), | ||
| sendEmail(name, email, message), |
There was a problem hiding this comment.
Preserve successful email-only contact delivery
When an existing deployment has working GMAIL_USER/GMAIL_PASSWORD settings but no contact-specific Discord webhook, sendDiscordWebhook rejects even though the concurrently executed email is successfully sent, and the rejection path returns 502. This regresses the previously supported email-only configuration, tells visitors to retry a message that was already emailed and persisted, and can create duplicate emails and database rows; treat the request as delivered when either configured channel succeeds, or skip an unconfigured webhook.
Useful? React with 👍 / 👎.
| const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY | ||
|
|
||
| if (!url || !serviceKey) return { url: fallbackUrl || '', message: '' } | ||
| const database = getServiceDatabase() |
There was a problem hiding this comment.
Catch service-client construction before using the fallback
If NEXT_PUBLIC_SUPABASE_URL is present but malformed, getServiceDatabase() throws while constructing the Supabase client, and that call now occurs outside the try block. Consequently the contact route fails before reaching the configured environment webhook and the comment route returns 502, even though this function is explicitly intended to fall back to environment variables when database-backed settings are unavailable; move client construction into the guarded section.
Useful? React with 👍 / 👎.
What changed
Why
Contact delivery returned early when Gmail was unavailable, so Discord never received the message. Comment delivery was fire-and-forget and ignored Discord errors. Both paths now use one verified server-side delivery flow.
Validation
npm run build