-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathnext.config.js
More file actions
45 lines (42 loc) · 1.57 KB
/
Copy pathnext.config.js
File metadata and controls
45 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const {PHASE_DEVELOPMENT_SERVER} = require('next/constants');
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,
basePath,
// Orb portals proxy the dev server through a different hostname.
allowedDevOrigins: process.env.PUBLIC_URL
? [new URL(process.env.PUBLIC_URL).hostname]
: [],
env: {
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
}
];
}
};
// withContentlayer is a webpack hook that regenerates .contentlayer when content
// changes, which `next dev --webpack` needs. `next build` uses Turbopack, with
// dev/build-content.mjs generating .contentlayer beforehand.
module.exports = phase =>
phase === PHASE_DEVELOPMENT_SERVER
? withContentlayer(nextConfig)
: nextConfig;