forked from hashicorp/dev-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
150 lines (143 loc) · 3.84 KB
/
next.config.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const fs = require('fs')
const path = require('path')
const withHashicorp = require('@hashicorp/platform-nextjs-plugin')
const withSwingset = require('swingset')
const { redirectsConfig } = require('./build-libs/redirects')
const rewritesConfig = require('./build-libs/rewrites')
const HashiConfigPlugin = require('./config/plugin')
// Set api key for Happy Kit feature flags
const happyKitKey = process.env.NEXT_PUBLIC_FLAGS_ENV_KEY
? process.env.NEXT_PUBLIC_FLAGS_ENV_KEY
: 'flags_pub_development_343442393171755603'
/**
* @type {import('next/dist/lib/load-custom-routes').Header}
*
* Adds a `noindex` directive to all pages for sentinel.
*
* e.g. If terraform and consul are the only products in the beta array, only developer.hashicorp.com/(consul|terraform)/* will get noindex
*/
const temporary_hideDocsPaths = {
source: `/(sentinel)/:path*`,
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex',
},
],
has: [
{
type: 'host',
value: 'developer.hashicorp.com',
},
],
}
/**
* @type {import('next/dist/lib/load-custom-routes').Header}
*
* Adds a `noindex` directive to all pages on `tip.waypointproject.io`.
* We don't want content on that domain to be indexed.
*/
const hideWaypointTipContent = {
source: '/:path*',
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex,nofollow',
},
],
has: [
{
type: 'host',
value: 'tip.waypointproject.io',
},
],
}
module.exports = withSwingset({
componentsRoot: 'src/components/**/*',
docsRoot: 'src/swingset-docs/*',
})(
withHashicorp({
nextOptimizedImages: true,
css: false,
transpileModules: [
'@hashicorp/flight-icons',
/**
* TODO: once Sentinel has been migrated into the dev-portal repository,
* we should consider localizing the sentinel-embedded component. Should
* first confirm with Cam Stitt that this component is not being used
* elsewhere.
*/
'@hashicorp/sentinel-embedded',
'swingset',
'unist-util-visit',
],
})({
webpack(config) {
config.plugins.push(HashiConfigPlugin())
return config
},
async headers() {
return [temporary_hideDocsPaths, hideWaypointTipContent]
},
async redirects() {
const { simpleRedirects, globRedirects } = await redirectsConfig()
await fs.promises.writeFile(
path.join('src', 'data', '_redirects.generated.json'),
JSON.stringify(simpleRedirects, null, 2),
'utf-8'
)
return globRedirects
},
async rewrites() {
const rewrites = await rewritesConfig()
if (process.env.DEBUG_REWRITES) {
await fs.promises.writeFile(
path.join('src', 'data', '_rewrites.generated.json'),
JSON.stringify(rewrites, null, 2),
'utf-8'
)
}
return rewrites
},
env: {
ASSET_API_ENDPOINT: process.env.ASSET_API_ENDPOINT,
AXE_ENABLED: process.env.AXE_ENABLED || false,
BUGSNAG_CLIENT_KEY: '06718db5e1d75829801baa0b4ca2fb7b',
BUGSNAG_SERVER_KEY: 'b32b4487b5dc72b32f51c8fe33641a43',
DEV_IO: process.env.DEV_IO,
PREVIEW_FROM_REPO: process.env.PREVIEW_FROM_REPO,
ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS || false,
HASHI_ENV: process.env.HASHI_ENV || 'development',
IS_CONTENT_PREVIEW: process.env.IS_CONTENT_PREVIEW,
MKTG_CONTENT_API: process.env.MKTG_CONTENT_API,
// TODO: determine if DevDot needs this or not
SEGMENT_WRITE_KEY: process.env.SEGMENT_WRITE_KEY,
HAPPY_KIT_KEY: happyKitKey,
},
svgo: {
plugins: [
{
removeViewBox: false,
collapseGroups: false,
},
],
},
images: {
formats: ['image/avif', 'image/webp'],
domains: [
'www.datocms-assets.com',
'mktg-content-api-hashicorp.vercel.app',
'content.hashicorp.com',
],
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
experimental: {
largePageDataBytes: 512 * 1000, // 512KB
},
})
)