-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
64 lines (55 loc) · 1.44 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
const isDev = process.env.NODE_ENV === 'development';
const storeUrl = process.env.NEXT_PUBLIC_SWELL_STORE_URL;
const graphqlKey = process.env.NEXT_PUBLIC_SWELL_PUBLIC_KEY;
/** @type {import('next').NextConfig} */
let nextConfig = {
reactStrictMode: true,
images: {
domains: [
'cdn.schema.io',
'cdn.swell.store',
...(isDev ? ['cdn.swell.test'] : []),
],
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack'],
});
return config;
},
rewrites() {
return [
{
destination: '/api/:slug*',
source: '/horizon-api/:slug*',
},
];
},
};
module.exports = async () => {
/**
*
* @returns @type {import('next').NextConfig['i18n']}
*/
const getLocalesConfig = async () => {
if (!storeUrl || !graphqlKey) return null;
const res = await fetch(`${storeUrl}/api/settings`, {
headers: {
Authorization: graphqlKey,
},
});
const data = await res.json();
if (!data?.store?.locales?.length) return null;
return {
locales: data.store.locales.map((locale) => locale.code),
defaultLocale: data.store.locales.map((locale) => locale.code)[0],
};
};
const i18n = await getLocalesConfig();
if (i18n) nextConfig.i18n = i18n;
return nextConfig;
};