-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathnext.config.js
More file actions
231 lines (222 loc) · 5.53 KB
/
next.config.js
File metadata and controls
231 lines (222 loc) · 5.53 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// @ts-check
const withNextIntl = require("next-intl/plugin")();
const nrExternals = require("@newrelic/next/load-externals");
/**
* Configure the base path for the app. Useful if you're deploying to a subdirectory (like GitHub Pages).
* If this is defined, you'll need to set the base path anywhere you use relative paths, like in
* `<a>`, `<img>`, or `<Image>` tags. Next.js handles this for you automatically in `<Link>` tags.
* @see https://nextjs.org/docs/api-reference/next.config.js/basepath
* @example "/test" results in "localhost:3000/test" as the index page for the app
*/
const basePath = process.env.NEXT_PUBLIC_BASE_PATH;
const cspHeader = `
default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
img-src 'self' blob: data:;
font-src 'self' https://fonts.gstatic.com;
object-src 'none';
connect-src 'self' https://bam.nr-data.net https://www.google-analytics.com;
base-uri 'self';
media-src 'self';
style-src-elem 'self' 'unsafe-inline' https://fonts.googleapis.com/;
script-src-elem 'self' 'unsafe-inline' https://www.googletagmanager.com/ https://fonts.googleapis.com/ https://js-agent.newrelic.com/;
form-action 'self';
frame-ancestors 'none';
upgrade-insecure-requests;
`;
const securityHeaders = [
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "Strict-Transport-Security",
value: "max-age=63072000; includeSubDomains; preload",
},
{
key: "Content-Security-Policy",
value: cspHeader.replace(/\n/g, ""),
},
{
key: "X-Frame-Options",
value: "SAMEORIGIN",
},
];
const headers = [
{
// static pages are stored for 6 hours, refreshed in the background for
// up to 10 minutes, and up to 12 hours if there is an error
source: "/:path*",
headers: [
{
key: "Cache-Control",
value:
"s-maxage=21600, stale-while-revalidate=600, stale-if-error=43200",
},
{
key: "Vary",
value: "Accept-Language",
},
],
},
// search page is stored 1 hour, stale 1 min, stale if error 5 mins
{
source: "/search",
headers: [
{
key: "Cache-Control",
value: "s-maxage=3600, stale-while-revalidate=60, stale-if-error=300",
},
],
},
// opportunity pages are stored 10 mins, stale 1 min, stale if error 5 mins
{
source: "/opportunity/:id(\\d{1,})",
headers: [
{
key: "Cache-Control",
value: "s-maxage=600, stale-while-revalidate=60, stale-if-error=300",
},
],
},
// don't cache the form
{
source: "/subscribe/:path*",
headers: [
{
key: "Cache-Control",
value: "no-store, must-revalidate",
},
],
},
// don't cache the api
{
source: "/api/:path*",
headers: [
{
key: "Cache-Control",
value: "no-store, must-revalidate",
},
],
},
// don't cache user specific pages: saved-opportunities, saved-search-queries
{
source: "/saved/:path*",
headers: [
{
key: "Cache-Control",
value: "no-store, must-revalidate",
},
],
},
// don't cache the user specific page for applications
{
source: "/applications",
headers: [
{
key: "Cache-Control",
value: "no-store, must-revalidate",
},
],
},
// don't cache if users has a session cookie
{
source: "/:path*",
has: [{ type: "cookie", key: "session" }],
headers: [
{
key: "Cache-Control",
value: "no-store, must-revalidate",
},
],
},
];
const isCi = Boolean(process.env.CI);
if (!isCi)
headers.push({
source: "/(.*)",
headers: securityHeaders,
});
const nextConfig = {
async headers() {
return headers;
},
// see https://nextjs.org/docs/messages/api-routes-response-size-limit
// warning about unrecognized key can be ignored
api: {
bodyParser: {
sizeLimit: "2000mb",
},
},
basePath,
reactStrictMode: true,
// Output only the necessary files for a deployment, excluding irrelevant node_modules
// https://nextjs.org/docs/app/api-reference/next-config-js/output
output: "standalone",
sassOptions: {
loadPaths: [
"./node_modules/@uswds",
"./node_modules/@uswds/uswds/packages",
],
},
serverExternalPackages: ["newrelic"],
webpack: (config) => {
nrExternals(config);
return config;
},
eslint: {
dirs: [
"src",
"stories",
".storybook",
"tests",
"scripts",
"frontend",
"lib",
"types",
],
},
experimental: {
testProxy: true,
proxyClientMaxBodySize: "2000mb",
serverActions: {
bodySizeLimit: "2000mb",
},
},
async redirects() {
return [
{
source: "/process",
destination: "/roadmap",
permanent: false,
},
{
source: "/subscribe",
destination: "/newsletter",
permanent: false,
},
{
source: "/subscribe/confirmation",
destination: "/newsletter/confirmation",
permanent: false,
},
{
source: "/subscribe/unsubscribe",
destination: "/newsletter/unsubscribe",
permanent: false,
},
{
source: "/organization/:segments*",
destination: "/organizations/:segments*",
permanent: false,
},
{
source: "/workspace/applications/application/:segments*",
destination: "/applications/:segments*",
permanent: false,
},
];
},
};
module.exports = withNextIntl(nextConfig);