From 1aed18031c1eb5d7080075ead1ad4589e49f75a2 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Fri, 11 Sep 2026 17:01:24 -0600 Subject: [PATCH] site: Redirect / to /docs on production deployments With basePath=/docs nothing serves /, so the *.vercel.app deployment URL that Vercel's Slack and GitHub posts link to returns a 404. Redirect it to /docs on the same host, so the visitor sees that exact deployment. Preview deployments (no basePath) are unchanged. Amp-Thread-ID: https://ampcode.com/threads/T-01a092ad-91c8-772e-bcba-a44caabb1653 Co-authored-by: Amp --- next.config.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/next.config.js b/next.config.js index ec00c3cd0..4a4b8636a 100644 --- a/next.config.js +++ b/next.config.js @@ -1,19 +1,34 @@ const {withContentlayer} = require('next-contentlayer2'); /** @type {import('next').NextConfig} */ +// in prod, we serve the docs from sourcegraph.com/docs, and this requires special config on the GFE side +// in preview/development, this is not necessary. +// +// VERCEL_ENV is a system env var set by Vercel +// https://vercel.com/docs/projects/environment-variables/system-environment-variables +const basePath = process.env.VERCEL_ENV === 'production' ? '/docs' : ''; + const nextConfig = { reactStrictMode: true, swcMinify: true, - // in prod, we serve the docs from sourcegraph.com/docs, and this requires special config on the GFE side - // in preview/development, this is not necessary. - // - // VERCEL_ENV is a system env var set by Vercel - // https://vercel.com/docs/projects/environment-variables/system-environment-variables - // basePath: process.env.VERCEL_ENV === 'production' ? '/docs' : '', - basePath: process.env.VERCEL_ENV === 'production' ? '/docs' : '', + basePath, env: { - NEXT_PUBLIC_DOCS_BASE_PATH: - process.env.VERCEL_ENV === 'production' ? '/docs' : '' + NEXT_PUBLIC_DOCS_BASE_PATH: basePath + }, + // With basePath set, nothing serves `/`, so the *.vercel.app deployment URL + // that Vercel links from Slack / GitHub 404s. sourcegraph.com never proxies + // `/` to us, so this only affects visitors opening that raw URL. Stay on the + // same host so they see this exact deployment, not whatever is live. + async redirects() { + if (!basePath) return []; + return [ + { + source: '/', + destination: basePath, + basePath: false, + permanent: false + } + ]; } };