fix(whitelabel): move redirects (build-time) for whitelabeling to middlware (runtime)#1236
fix(whitelabel): move redirects (build-time) for whitelabeling to middlware (runtime)#1236waleedlatif1 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical whitelabeling issue by moving terms and privacy page redirects from build-time configuration to runtime middleware. The change addresses a fundamental limitation where Next.js redirects in next.config.ts are baked into the application bundle at build time, preventing whitelabeled deployments from dynamically configuring their own legal page URLs.
The implementation adds new logic to middleware.ts that checks for NEXT_PUBLIC_TERMS_URL and NEXT_PUBLIC_PRIVACY_URL environment variables at request time. When users visit /terms or /privacy routes, the middleware now evaluates these environment variables and redirects to external URLs if they start with 'http'. This enables customers to provide their own terms of service and privacy policy URLs without requiring a rebuild.
The corresponding build-time redirect logic is removed from next.config.ts, including the getEnv import that's no longer needed. The middleware matcher configuration is updated to include the new /terms and /privacy paths, ensuring these routes are properly handled by the runtime logic.
This change transforms whitelabeling from a build-time feature to a runtime feature, allowing for true dynamic configuration of legal page URLs through environment variables.
Confidence score: 4/5
- This PR addresses a legitimate architectural issue and should work as intended with minimal risk
- Score reflects solid implementation of a straightforward redirect pattern, though runtime environment variable access could have edge cases
- Pay close attention to environment variable handling and ensure proper fallback behavior when URLs are not configured
2 files reviewed, no comments
Summary
move redirects (build-time) for whitelabeling to middlware (runtime), this allows for people to bring their own privacy policy & terms URLs because otherwise, the next config is bundled in at build time, which doesn't actually bundle their redirects in if its in next config
Type of Change
Testing
Tested manually.
Checklist