-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnext.config.js
265 lines (249 loc) · 8.62 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/* eslint-disable @typescript-eslint/no-var-requires */
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const { withSentryConfig } = require('@sentry/nextjs');
const helmet = require('helmet');
const isGithubCI = process.env.NODE_ENV === 'production' && process.env.GITHUB_CI === 'true';
const csp = {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
'script-src': [
"'self'",
"'sha256-TXnVHDn1j7ztxp+9fAgGYQt5MDdGcfG3DMT2sJR4v/I='",
"'sha256-uoDYfYhkG1Rred64INgKWU540cb8GBpVb+EoZcz/Zyo='",
"'sha256-eGdlwoVjdfoAxTtVJ5JOqj8MsevToXdxA0rkY5IXIxk='",
"'sha256-5nUSiKlxGJiE3JicLfPYxYZShtQfFZM0jtHZyyPijTE='",
"'sha256-PAh6kZHWrs47demJXB9x6PfCgghwAf4BZ4ncKf/BhiU='",
"'sha256-vHLisyhJqlXs8efpQOmla3M8/VBRwdzde5ZgWIhJQEA='",
"'sha256-3I33qFPfa/PLrN/3rrrC4vJBjmKYiuXWQ+ZfnHiEWmo='",
"'sha256-ksltjYbI6Uoozfn80t6ROvA1rBbTP9X8qGPGwHmWBpA='",
"'sha256-6SC04Y6nNQLzwzyqa3SfGlAJoGLEAasou2bnNnkusvM='",
"'sha256-b4GFU36HxV/ajsLtGxYpBvVIlonNc0Dz5lk+ZTMKysY='", // PROD - Facebook Pixel 3064783047067401
"'sha256-Ny4QAH1g1FWyqlgrnIVWh1mj+jM8c6SjgqJ2i6c2REU='", // PROD - google analytics common
"'sha256-8r71P9EINuYzK2mdhvMfZG0nDrKZhY5rvxXNAgVD45g='", // PROD - Google AW-16641573937
"'sha256-/To7QTI1yR8LpZjhrqYdP21zirnpAwwI4s7M8TwKxnI='", // PROD - Google G-B35Q28PSV8
"'sha256-/CSSb6w0OrYpmMov6mf2agdZaX5CEjsuUL45DW0yKI4='", // PROD - Hotjar 3874965 6
"'sha256-cLrFOA9eDIz+hTs9m3AUrlzvroRre9vJ4cvv1ygI/Bw='", // PROD - LinkedIn 3494650
"'sha256-cWPc/BJwUWRnFb5b17VxDNk72/ZwL1GOqTQ6dAU/P3E='", // PROD - unknown yet
'https://stats.data.gouv.fr',
'https://stats.beta.gouv.fr',
'https://static.axept.io',
'https://connect.facebook.net',
'https://www.gstatic.com/',
'https://www.googletagmanager.com https://*.googletagmanager.com',
'https://www.googleadservices.com',
'https://googleads.g.doubleclick.net',
'https://connect.facebook.net',
'https://snap.licdn.com',
'https://api.mapbox.com/',
'https://*.hotjar.com',
],
'connect-src': [
"'self'",
'https://openmaptiles.geo.data.gouv.fr',
'https://openmaptiles.data.gouv.fr',
'https://openmaptiles.github.io',
'https://france-chaleur-urbaine.beta.gouv.fr/',
'https://france-chaleur-urbaine-dev.osc-fr1.scalingo.io/',
'https://api-adresse.data.gouv.fr/',
'https://stats.data.gouv.fr',
'https://stats.beta.gouv.fr',
'https://cdn.linkedin.oribi.io',
'https://google.com/',
'https://px.ads.linkedin.com',
'https://data.geopf.fr',
'https://api.mapbox.com/',
'https://sentry.incubateur.net',
'https://*.hotjar.com https://*.hotjar.io wss://*.hotjar.com',
'https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com',
],
'img-src': ["'self'", 'https:', 'data:'],
'font-src': ["'self'", 'https:', 'data:', 'https://*.hotjar.com'],
'frame-src': ['https://td.doubleclick.net', 'https://www.facebook.com/', 'https://www.youtube.com/'],
'style-src': ["'self'", 'https:', "'unsafe-inline'", 'https://*.hotjar.com'],
'worker-src': ["'self'", 'blob:'],
};
if (process.env.UNSAFE_EVAL === 'true') {
csp['script-src'].push("'unsafe-eval'");
}
const securityHeaders = [
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN',
},
{
key: 'Content-Security-Policy',
value: Object.keys(csp)
.map((key) => `${key} ${csp[key].join(' ')}`)
.join(';'),
},
];
const securityHeadersIFramable = [
{
key: 'X-Frame-Options',
value: '',
},
{
key: 'Content-Security-Policy',
value: Object.keys(csp)
.filter((key) => key !== 'frame-ancestors')
.map((key) => `${key} ${csp[key].join(' ')}`)
.join(';'),
},
];
module.exports = withBundleAnalyzer(
withSentryConfig(
{
compiler: {
styledComponents: true,
},
assetPrefix: isGithubCI ? '/france-chaleur-urbaine/' : undefined,
basePath: isGithubCI ? '/france-chaleur-urbaine' : undefined,
eslint: {
ignoreDuringBuilds: true,
},
// too many conflicts with map draw listeners
// reactStrictMode: true,
async redirects() {
return [
{
source: '/guide-france-chaleur-urbaine',
destination: '/documentation/guide-france-chaleur-urbaine.pdf',
permanent: false,
},
// redirections for pages that were removed
{
source: '/statistiques',
destination: '/stats',
permanent: true,
},
{
source: '/accueil',
destination: '/',
permanent: true,
},
{
source: '/coproprietaire',
destination: '/',
permanent: true,
},
{
source: '/conseiller',
destination: '/professionnels',
permanent: true,
},
{
source: '/ressources',
destination: '/ressources/articles',
permanent: true,
},
{
source: '/evos',
destination: '/campagnes2024',
permanent: true,
},
];
},
async headers() {
return [
{
source: '/:path*',
headers: securityHeaders,
},
{
source: '/openapi-schema.yaml',
headers: [
{
key: 'Access-Control-Allow-Methods',
value: 'GET, OPTIONS',
},
{
key: 'Access-Control-Allow-Origin',
value: '*',
},
],
},
// Attention: keep in sync with src/services/iframe.ts
...[
'/carte-collectivite',
'/charleville-mezieres',
'/dalkia',
'/engie',
'/form',
'/idex',
'/map',
'/page-reseaux/:network',
'/viaseva',
].map((source) => ({
source,
headers: securityHeadersIFramable,
})),
];
},
webpack: (config) => {
config.module.rules.push({
test: /\.md$/,
use: 'raw-loader',
});
config.module.rules.push({
test: /\.woff2$/,
type: 'asset/resource',
});
// https://github.com/gregberge/svgr/issues/860#issuecomment-1653928947
// This is done to prevent DSFR Display component to fail with undefined URL for SVG See https://github.com/betagouv/france-chaleur-urbaine/pull/882
// In order to load a SVG, you will need to suffix it with ?icon
// example: `import IconPotentiel from '@/public/icons/potentiel.svg?icon';`
const nextImageLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'));
nextImageLoaderRule.resourceQuery = {
not: [...nextImageLoaderRule.resourceQuery.not, /icon/],
};
config.module.rules.push({
issuer: nextImageLoaderRule.issuer,
resourceQuery: /icon/, // *.svg?icon
use: ['@svgr/webpack'],
});
return config;
},
transpilePackages: ['@codegouvfr/react-dsfr'],
},
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
dryRun: !process.env.NEXT_PUBLIC_SENTRY_DSN,
// Suppresses source map uploading logs during build
silent: true,
org: 'betagouv',
project: 'fcu-prod',
url: 'https://sentry.incubateur.net/',
// do not exit if the build fails to interact with the sentry server
errorHandler: (err, invokeErr, compilation) => {
compilation.warnings.push('Sentry CLI Plugin: ' + err.message);
},
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: false,
// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: false,
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
// Enables automatic instrumentation of Vercel Cron Monitors.
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
}
)
);