feat: add WEBAPP_URL_INTERNAL for server-side self-fetches - #29840
feat: add WEBAPP_URL_INTERNAL for server-side self-fetches#29840GAURAV07C wants to merge 4 commits into
Conversation
|
Welcome to Cal.diy, @GAURAV07C! Thanks for opening this pull request. A few things to keep in mind:
A maintainer will review your PR soon. Thanks for contributing! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds the optional 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/trpc/react/trpc.ts`:
- Around line 55-62: Normalize and validate WEBAPP_URL_INTERNAL before appending
endpoint paths or passing it to URL-based self-fetches. Apply this in
packages/trpc/react/trpc.ts around internalUrl,
apps/web/app/api/social/og/image/route.tsx at lines 40-42 before new URL(...),
and apps/web/server/lib/auth/verify-email-change/getServerSideProps.tsx at line
29 before composing the verification endpoint; host-only values such as
localhost:3000 must become valid URLs while preserving already normalized
values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0b7c1d84-6430-459c-85fe-4d6db5c32d54
📒 Files selected for processing (4)
apps/web/app/api/social/og/image/route.tsxapps/web/server/lib/auth/verify-email-change/getServerSideProps.tsxpackages/trpc/react/trpc.tspackages/types/environment.d.ts
…ndardized URL constants
…7C/cal.diy into feat/webapp-url-internal
|
@bandhan-majumder can you review ? |
Description
The Problem:
Currently, when the container makes server-side HTTP calls to itself during SSR (such as tRPC queries, OG image font fetches, or email verification flows), it uses the public
WEBAPP_URL. When the container sits behind a reverse proxy or CDN (like Cloudflare or nginx), these internal calls are routed all the way out to the public IP and back to the same container (hairpin routing). This causes:The Solution:
Similar to how NextAuth handles its own SSR fetches with
NEXTAUTH_URL_INTERNAL, this PR introduces a new environment variable:WEBAPP_URL_INTERNAL.When
WEBAPP_URL_INTERNALis set (e.g.http://localhost:3000), server-side code uses it in place of the publicWEBAPP_URLfor its internal HTTP requests. Client-facing URL generation remains unaffected and strictly usesWEBAPP_URL.Changes Made:
environment.d.ts: Added type definition forWEBAPP_URL_INTERNAL.packages/trpc/react/trpc.ts: Updated the tRPC Next.js client initialization to prioritizeWEBAPP_URL_INTERNALduring SSR evaluations.getServerSideProps(verify-email-change) & OG image font fetching (route.tsx): Updated server-sidefetch()logic to securely fall back to the internal URL.Backwards Compatibility
If
WEBAPP_URL_INTERNALis unset, the system seamlessly falls back to using the standardWEBAPP_URLinternally. Existing deployments will keep working as before without any breaking changes.Fixes #29834
Type of change
Checklist
yarn type-check:ci --forceand ensured there are no TypeScript errors