-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
79 lines (75 loc) · 2.09 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
const nextTranslate = require('next-translate')
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
options: {
remarkPlugins: [],
rehypePlugins: [],
},
})
const mdx = withMDX({
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
})
const getUrlWithoutPath = (url) => {
if (!url) return ''
try {
const newUrl = new URL(url)
return `${newUrl.protocol}//${newUrl.hostname}`
} catch (error) {
console.error(error)
return ''
}
}
module.exports = nextTranslate({
...mdx,
async headers() {
const baseUrl = getUrlWithoutPath(process.env.NEXT_PUBLIC_BASE_URL)
const vercelUrl = getUrlWithoutPath(`https://${process.env.VERCEL_URL}`)
const matomoUrl = getUrlWithoutPath(process.env.NEXT_PUBLIC_MATOMO_URL)
const tilesUrl = getUrlWithoutPath(process.env.NEXT_PUBLIC_TREE_TILES_URL)
const basemapUrl = getUrlWithoutPath(
process.env.NEXT_PUBLIC_MAPTILER_BASEMAP_URL
)
const postgrestUrl = getUrlWithoutPath(
`${process.env.ML_PGREST_HOST}:${process.env.ML_PGREST_PORT}`
)
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: [
`default-src 'self'`,
`script-src 'self' 'unsafe-eval'`,
`style-src 'self' 'unsafe-inline'`,
`font-src 'self' data:`,
`img-src 'self' ${[
baseUrl,
vercelUrl,
matomoUrl,
tilesUrl,
basemapUrl,
postgrestUrl,
]
.filter(Boolean)
.join(' ')} data: blob:`,
`frame-ancestors 'none'`,
`worker-src 'self' blob:`,
`child-src 'self' blob:`,
`connect-src 'self' ${[
baseUrl,
vercelUrl,
tilesUrl,
basemapUrl,
matomoUrl,
postgrestUrl,
]
.filter(Boolean)
.join(' ')}`,
].join('; '),
},
],
},
]
},
})