feat(middleware): redirect production build URLs to canonical host - #19033
Merged
Conversation
Option B for contractor preview access: instead of gating previews with Vercel Deployment Protection, keep previews publicly accessible and lock down only the generated *production* build URLs in middleware. With Deployment Protection off, generated production URLs (e.g. sentry-docs-<hash>.vercel.app) would be publicly accessible and indexable as a separate copy of the site. This adds an early check in the existing middleware that, on production deployments only, 308-redirects any request whose host isn't the canonical domain (docs.sentry.io / develop.sentry.dev) to that domain, preserving path and query. - Preview deployments are untouched and stay publicly accessible, so contractors open PR previews with zero extra steps (no share links). - Only GET requests are redirected; API/cron/webhook traffic is unaffected. - VERCEL_ENV is inlined into the edge bundle via next.config.ts `env` (edge runtime can't read server env vars at request time). - Complements the existing X-Robots-Tag: noindex on non-canonical hosts. Requires turning OFF Vercel Standard Protection so previews are reachable. Adds 7 middleware tests (21 total passing).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reword the next.config.ts and middleware.ts comments to describe the VERCEL_ENV `env` entry as deliberate build-time freezing of a per-deployment-constant value (following the DEVELOPER_DOCS convention), rather than claiming the Edge runtime can't read server env vars. Vercel exposes VERCEL_ENV at build and runtime when "Automatically expose System Environment Variables" is enabled (the default); the freeze is a stability choice, not a workaround. No behavior change.
sfanahata
marked this pull request as ready for review
August 12, 2026 22:22
sergical
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DESCRIBE YOUR PR
Problem: Contractors need to view PR previews, but with Vercel Deployment Protection off, generated production build URLs (for example,
sentry-docs-<hash>.vercel.app) are also publicly accessible and indexable as a duplicate copy of the site.Solution: In the existing
middleware.ts, on production deployments only,308-redirect GET and HEAD page requests whose host is not the canonical domain (docs.sentry.io/develop.sentry.dev) to that domain, preserving path and query.VERCEL_ENVis deliberately frozen into the bundle throughnext.config.ts; it is constant per deployment.X-Robots-Tag: noindexon non-canonical hosts.This is an SEO/canonicalization measure, not a security boundary. Existing production deployments will be deleted before protection is disabled because immutable older deployments do not contain this middleware.
Required: Turn off Vercel Standard Protection after this is deployed and old production deployments are deleted so previews are publicly reachable.
IS YOUR CHANGE URGENT?
PRE-MERGE CHECKLIST
LEGAL BOILERPLATE
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
EXTRA RESOURCES