-
Notifications
You must be signed in to change notification settings - Fork 12
/
next.config.mjs
180 lines (162 loc) · 5 KB
/
next.config.mjs
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
import NextBundleAnalyzer from '@next/bundle-analyzer';
import buildDynamics from './scripts/build-dynamics.mjs';
import { logEnvironmentVariables } from './scripts/log-environment-variables.mjs';
import generateBuildId from './scripts/generate-build-id.mjs';
import { startupCheckRPCs } from './scripts/startup-checks/rpc.mjs';
logEnvironmentVariables();
buildDynamics();
if (
process.env.RUN_STARTUP_CHECKS === 'true' &&
typeof window === 'undefined'
) {
void startupCheckRPCs();
}
// https://nextjs.org/docs/pages/api-reference/next-config-js/basePath
const basePath = process.env.BASE_PATH;
const developmentMode = process.env.NODE_ENV === 'development';
const isIPFSMode = process.env.IPFS_MODE === 'true';
// cache control
export const CACHE_CONTROL_HEADER = 'x-cache-control';
export const CACHE_CONTROL_PAGES = [
'/manifest.json',
'/favicon:size*',
'/',
'/wrap',
'/wrap/unwrap',
'/rewards',
'/referral',
'/withdrawals/request',
'/withdrawals/claim',
'/runtime/window-env.js',
];
export const CACHE_CONTROL_VALUE =
'public, max-age=15, s-max-age=30, stale-if-error=604800, stale-while-revalidate=172800';
const withBundleAnalyzer = NextBundleAnalyzer({
enabled: process.env.ANALYZE_BUNDLE ?? false,
});
export default withBundleAnalyzer({
basePath,
generateBuildId,
// IPFS next.js configuration reference:
// https://github.com/Velenir/nextjs-ipfs-example
trailingSlash: !!isIPFSMode,
assetPrefix: isIPFSMode ? './' : undefined,
// IPFS version has hash-based routing,
// so we provide only index.html in ipfs version
exportPathMap: isIPFSMode ? () => ({ '/': { page: '/' } }) : undefined,
eslint: {
ignoreDuringBuilds: true,
},
compiler: {
styledComponents: true,
},
experimental: {
// Fixes a build error with importing Pure ESM modules, e.g. reef-knot
// Some docs are here:
// https://github.com/vercel/next.js/pull/27069
// You can see how it is actually used in v12.3.4 here:
// https://github.com/vercel/next.js/blob/v12.3.4/packages/next/build/webpack-config.ts#L417
// Presumably, it is true by default in next v13 and won't be needed
esmExternals: true,
newNextLinkBehavior: true,
},
webpack(config) {
config.module.rules.push(
// Teach webpack to import svg and md files
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
},
{
test: /\.md$/,
use: 'raw-loader',
},
// Needs for `Conditional Compilation`,
// because we have differences in source code of IPFS widget and NOT IPFS widget
{
test: /\.(t|j)sx?$/,
use: [
{
loader: 'webpack-preprocessor-loader',
options: {
params: {
IPFS_MODE: isIPFSMode,
},
},
},
],
},
);
return config;
},
async headers() {
return [
{
// Apply these headers to all routes in your application.
source: '/(.*)',
headers: [
{
key: 'X-DNS-Prefetch-Control',
value: 'on',
},
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{
key: 'Referrer-Policy',
value: 'same-origin',
},
{
key: 'x-content-type-options',
value: 'nosniff',
},
{ key: 'x-xss-protection', value: '1' },
{ key: 'x-download-options', value: 'noopen' },
],
},
{
// required for gnosis save apps
source: '/manifest.json',
headers: [{ key: 'Access-Control-Allow-Origin', value: '*' }],
},
...CACHE_CONTROL_PAGES.map((page) => ({
source: page,
headers: [{ key: CACHE_CONTROL_HEADER, value: CACHE_CONTROL_VALUE }],
})),
];
},
redirects: () => [
{
source: '/withdrawals',
destination: '/withdrawals/request',
permanent: false,
},
],
// ATTENTION: If you add a new variable you should declare it in `global.d.ts`
serverRuntimeConfig: {
// https://nextjs.org/docs/pages/api-reference/next-config-js/basePath
basePath,
developmentMode,
// ETH rpcs
defaultChain: process.env.DEFAULT_CHAIN,
rpcUrls_1: process.env.EL_RPC_URLS_1,
rpcUrls_17000: process.env.EL_RPC_URLS_17000,
rpcUrls_11155111: process.env.EL_RPC_URLS_11155111,
// OP rpcs
rpcUrls_10: process.env.EL_RPC_URLS_10,
rpcUrls_11155420: process.env.EL_RPC_URLS_11155420,
cspTrustedHosts: process.env.CSP_TRUSTED_HOSTS,
cspReportUri: process.env.CSP_REPORT_URI,
cspReportOnly: process.env.CSP_REPORT_ONLY,
rateLimit: process.env.RATE_LIMIT,
rateLimitTimeFrame: process.env.RATE_LIMIT_TIME_FRAME,
ethAPIBasePath: process.env.ETH_API_BASE_PATH,
rewardsBackendAPI: process.env.REWARDS_BACKEND,
},
// ATTENTION: If you add a new variable you should declare it in `global.d.ts`
publicRuntimeConfig: {
basePath,
developmentMode,
},
});