Skip to content

fix(whitelabel): move redirects (build-time) for whitelabeling to middlware (runtime)#1236

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/wl
Sep 3, 2025
Merged

fix(whitelabel): move redirects (build-time) for whitelabeling to middlware (runtime)#1236
waleedlatif1 merged 1 commit intostagingfrom
fix/wl

Conversation

@waleedlatif1
Copy link
Collaborator

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

  • Bug fix

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Sep 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 3, 2025 7:55pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 3, 2025 7:55pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 1de5966 into staging Sep 3, 2025
5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/wl branch September 3, 2025 23:36
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant