forked from Sitecore/developer-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
111 lines (106 loc) · 3.4 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
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* @type {import('next').NextConfig}
*/
const fs = require('fs');
const path = require('path');
//const withTM = require('next-transpile-modules'); // pass the modules you would like to see transpiled
const securityHeaders = [
{
key: 'Content-Security-Policy',
value:
"default-src 'self' data: blob: *.sitecore.com *.sitecore.net *.stylelabs.cloud *.googleapis.com *.gstatic.com *.azureedge.net; frame-src * 'self' 'unsafe-inline'; frame-ancestors 'self' https://*.sitecore.com; script-src * blob: data: 'self' 'unsafe-inline' 'unsafe-eval'; script-src-elem * 'self' 'unsafe-inline'; script-src-attr * 'self' 'unsafe-inline'; style-src * 'self' 'unsafe-inline'; style-src-elem * 'self' 'unsafe-inline'; style-src-attr * 'self' 'unsafe-inline' data:; img-src * 'self' 'unsafe-inline' data:; font-src * data: 'self' 'unsafe-inline'; connect-src *; object-src 'none'; media-src * data: blob: 'unsafe-inline' 'unsafe-eval';",
},
{
key: 'Referrer-Policy',
value: 'same-origin',
},
{
key: 'Permissions-Policy',
value:
'accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
];
const redirects = [
{
source: '/learn/integrations/xm-cdp',
destination: '/learn/integrations/xm-smarthub-cdp',
permanent: true,
},
];
const nextConfig = {
// Set locales so we have appropriate lang attributes without a custom _document
// ia8n commentted out due to temporary issue with ISR, see https://github.com/Sitecore/developer-portal/issues/182
// i18n: {
// locales: ['en'],
// defaultLocale: 'en',
// },
// Needed to expose in clientside.
env: {
GTM_ID: process.env.GTM_ID,
GTM_AUTH: process.env.GTM_AUTH,
GTM_ENVIRONMENT: process.env.GTM_ENVIRONMENT,
COVEO_ACCESS_TOKEN: process.env.COVEO_ACCESS_TOKEN,
COVEO_ORGANIZATION_ID: process.env.COVEO_ORGANIZATION_ID,
COVEO_PIPELINE: process.env.COVEO_PIPELINE,
COVEO_SEARCH_HUB: process.env.COVEO_SEARCH_HUB,
},
images: {
dangerouslyAllowSVG: true,
domains: [
'sitecorecdn.azureedge.net',
'i.ytimg.com',
'mss-p-006-delivery.sitecorecontenthub.cloud',
'mss-p-006-delivery.stylelabs.cloud',
'go.sitecore.com',
],
deviceSizes: [640, 750, 828, 1080, 1200, 1920],
},
async headers() {
return [
{
source: '/(.*)',
headers: securityHeaders,
},
];
},
async redirects() {
// Get the latest newsletter and redirect `newsletter/latest` to it
const newsletterDataDir = path.resolve(__dirname, 'data/newsletters/');
const year = fs
.readdirSync(newsletterDataDir)
.map((y) => parseInt(y, 10))
.sort((a, b) => b - a)[0];
const month = fs
.readdirSync(path.resolve(newsletterDataDir, `${year}`))
.map((m) => {
const name = m.substring(m, m.length - 5);
return {
name,
num: parseInt(name, 10),
};
})
.sort((a, b) => b.num - a.num)[0].name;
return [
...redirects,
{
source: '/newsletter/latest',
destination: `/newsletter/${year}/${month}`,
permanent: false,
},
];
},
};
module.exports = nextConfig;