forked from solana-foundation/solana-com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
177 lines (168 loc) · 4.31 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
/**
* @type {import('next').NextConfig}
**/
const withBundleAnalyzer = require("@next/bundle-analyzer");
const { i18n } = require("./next-i18next.config");
const rewritesAndRedirectsJson = require("./rewrites-redirects.json");
const { builder } = require("@builder.io/sdk");
const securityHeaders = [
{
key: "X-Frame-Options",
value: "SAMEORIGIN",
},
{
key: "X-XSS-Protection",
value: "1; mode=block",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "Content-Security-Policy",
value:
"frame-ancestors https://*.builder.io https://builder.io http://localhost:1234",
},
];
// `X-Robots-Tag: noindex` will not be set by default for custom domains
// https://vercel.com/guides/are-vercel-preview-deployment-indexed-by-search-engines
if (process.env.NEXT_PUBLIC_VERCEL_ENV === "preview") {
securityHeaders.push({
key: "X-Robots-Tag",
value: "noindex",
});
}
const moduleExports = () => {
const plugins = [
withBundleAnalyzer({ enabled: process.env.ANALYZE === "true" }),
];
return plugins.reduce((acc, next) => next(acc), {
i18n,
reactStrictMode: true,
swcMinify: true,
productionBrowserSourceMaps: true,
async rewrites() {
return rewritesAndRedirectsJson.rewrites;
},
async redirects() {
const existingRedirects = [
{
source: "/news/tag/:tag*/page/:page*",
destination: `/news/tag/:tag*`,
permanent: true,
},
{
source: "/news/tag",
destination: `/news`,
permanent: true,
},
{
source: "/news/page",
destination: `/news`,
permanent: true,
},
...rewritesAndRedirectsJson.redirects.map((redirect) => ({
...redirect,
// @ts-ignore
permanent: redirect.permanent ?? true,
})),
];
return builder
.getAll("url-redirects", {
apiKey:
process.env.NEXT_PUBLIC_BUILDER_API_KEY ||
"ce0c7323a97a4d91bd0baa7490ec9139",
options: { noTargeting: true },
cachebust: true,
})
.then(
(results) => [
...existingRedirects,
...results
.filter((content) => {
const data = (content || {}).data || {};
return !!(data.sourceUrl && data.destinationUrl);
})
.map(({ data }) => ({
source: data.sourceUrl,
destination: data.destinationUrl,
permanent: !!data.permanentRedirect,
})),
],
(error) => {
console.log("Error setting up redirects", error);
return existingRedirects;
},
);
},
webpack(config) {
config.module.rules.push({
test: /\.inline\.svg$/,
exclude: /node_modules/,
loader: "svg-react-loader",
});
const imageLoaderRule = config.module.rules.find(
(rule) => rule.loader == "next-image-loader",
);
imageLoaderRule.exclude = /\.inline\.svg$/;
return config;
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "i.ytimg.com",
},
{
protocol: "https",
hostname: "img.youtube.com",
},
{
protocol: "https",
hostname: "**.gstatic.com",
},
{
protocol: "https",
hostname: "**.lumacdn.com",
},
{
protocol: "https",
hostname: "**.lu.ma",
},
{
protocol: "https",
hostname: "cdn.builder.io",
},
{
protocol: "https",
hostname: "solana-developer-content.vercel.app",
},
{
protocol: "https",
hostname: "images.unsplash.com",
},
{
protocol: "https",
hostname: "assets.getriver.io",
},
],
},
compiler: {
// ssr and displayName are configured by default
styledComponents: true,
},
async headers() {
return [
{
// Apply headers to all routes
source: "/:path*",
headers: securityHeaders,
},
];
},
experimental: {
scrollRestoration: true,
},
});
};
module.exports = moduleExports;