Refactor API hooks to use dynamic base URL for hosted environments#526
Refactor API hooks to use dynamic base URL for hosted environments#526softmarshmallow merged 1 commit intomainfrom
Conversation
Update the API hooks in the submission process to utilize a dynamic base URL that adapts based on the hosting environment. This change prevents potential 401 errors when accessing protected domains and ensures the GRIDA S2S private API key is safely handled. Additionally, clean up the handling of the API key in the notification email route for improved security.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis pull request refactors webhook endpoint handling by introducing a conditional base URL mechanism for API calls and simplifying authentication header extraction. The GRIDA_S2S_PRIVATE_API_KEY environment variable now defaults to null when undefined, and the header validation logic is streamlined to use a single key. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f38c6386a3
ℹ️ 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".
| const GRIDA_S2S_PRIVATE_API_KEY = process.env.GRIDA_S2S_PRIVATE_API_KEY; | ||
| // In hosted env, avoid calling the deployment domain (`*.vercel.app`) since it | ||
| // can be protected upstream (401) even when our app routes would allow it. | ||
| const HOOK_BASE_URL = Env.server.IS_HOSTED ? Env.web.HOST : Env.server.HOST; |
There was a problem hiding this comment.
Keep hook callbacks on the active deployment host
Switching HOOK_BASE_URL to Env.web.HOST in hosted mode can send hook requests to a different environment than the one that processed the submission (for example when NEXT_PUBLIC_URL is a canonical domain but the request is handled by a preview/canary deployment). In that case response_id/form_id lookups happen against the wrong backend and post-submit side effects (session clear, post-indexing, respondent email) are dropped even though submit succeeded. Using the current deployment host (Env.server.HOST) or a deployment-aware fallback avoids cross-environment drift.
Useful? React with 👍 / 👎.
Update the API hooks in the submission process to utilize a dynamic base URL that adapts based on the hosting environment. This change prevents potential 401 errors when accessing protected domains and ensures the GRIDA S2S private API key is safely handled. Additionally, clean up the handling of the API key in the notification email route for improved security.
Summary by CodeRabbit
Bug Fixes
Chores