Skip to content

Commit 3b689d4

Browse files
authored
[Dashboard] Fix: next config memory cache (#5906)
1 parent 2d996cc commit 3b689d4

File tree

1 file changed

+180
-184
lines changed

1 file changed

+180
-184
lines changed

apps/dashboard/next.config.ts

Lines changed: 180 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -19,208 +19,204 @@ const ContentSecurityPolicy = `
1919
`;
2020

2121
const securityHeaders = [
22-
{
23-
key: "X-DNS-Prefetch-Control",
24-
value: "on",
25-
},
26-
{
27-
key: "X-XSS-Protection",
28-
value: "1; mode=block",
29-
},
30-
{
31-
key: "X-Frame-Options",
32-
value: "SAMEORIGIN",
33-
},
34-
{
35-
key: "Referrer-Policy",
36-
value: "origin-when-cross-origin",
37-
},
38-
{
39-
key: "Content-Security-Policy",
40-
value: ContentSecurityPolicy.replace(/\s{2,}/g, " ").trim(),
41-
},
22+
{
23+
key: "X-DNS-Prefetch-Control",
24+
value: "on",
25+
},
26+
{
27+
key: "X-XSS-Protection",
28+
value: "1; mode=block",
29+
},
30+
{
31+
key: "X-Frame-Options",
32+
value: "SAMEORIGIN",
33+
},
34+
{
35+
key: "Referrer-Policy",
36+
value: "origin-when-cross-origin",
37+
},
38+
{
39+
key: "Content-Security-Policy",
40+
value: ContentSecurityPolicy.replace(/\s{2,}/g, " ").trim(),
41+
},
4242
];
4343

4444
function determineIpfsGateways() {
45-
// add the clientId ipfs gateways
46-
const remotePatterns: RemotePattern[] = [];
47-
if (process.env.API_ROUTES_CLIENT_ID) {
48-
remotePatterns.push({
49-
protocol: "https",
50-
hostname: `${process.env.API_ROUTES_CLIENT_ID}.ipfscdn.io`,
51-
});
52-
remotePatterns.push({
53-
protocol: "https",
54-
hostname: `${process.env.API_ROUTES_CLIENT_ID}.thirdwebstorage-staging.com`,
55-
});
56-
remotePatterns.push({
57-
protocol: "https",
58-
hostname: `${process.env.API_ROUTES_CLIENT_ID}.thirdwebstorage-dev.com`,
59-
});
60-
} else {
61-
// this should only happen in development
62-
remotePatterns.push({
63-
protocol: "https",
64-
hostname: "ipfs.io",
65-
});
66-
}
67-
// also add the dashboard clientId ipfs gateway if it is set
68-
if (process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID) {
69-
remotePatterns.push({
70-
protocol: "https",
71-
hostname: `${process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID}.ipfscdn.io`,
72-
});
73-
remotePatterns.push({
74-
protocol: "https",
75-
hostname: `${process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID}.thirdwebstorage-staging.com`,
76-
});
77-
remotePatterns.push({
78-
protocol: "https",
79-
hostname: `${process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID}.thirdwebstorage-dev.com`,
80-
});
81-
}
82-
return remotePatterns;
45+
// add the clientId ipfs gateways
46+
const remotePatterns: RemotePattern[] = [];
47+
if (process.env.API_ROUTES_CLIENT_ID) {
48+
remotePatterns.push({
49+
protocol: "https",
50+
hostname: `${process.env.API_ROUTES_CLIENT_ID}.ipfscdn.io`,
51+
});
52+
remotePatterns.push({
53+
protocol: "https",
54+
hostname: `${process.env.API_ROUTES_CLIENT_ID}.thirdwebstorage-staging.com`,
55+
});
56+
remotePatterns.push({
57+
protocol: "https",
58+
hostname: `${process.env.API_ROUTES_CLIENT_ID}.thirdwebstorage-dev.com`,
59+
});
60+
} else {
61+
// this should only happen in development
62+
remotePatterns.push({
63+
protocol: "https",
64+
hostname: "ipfs.io",
65+
});
66+
}
67+
// also add the dashboard clientId ipfs gateway if it is set
68+
if (process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID) {
69+
remotePatterns.push({
70+
protocol: "https",
71+
hostname: `${process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID}.ipfscdn.io`,
72+
});
73+
remotePatterns.push({
74+
protocol: "https",
75+
hostname: `${process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID}.thirdwebstorage-staging.com`,
76+
});
77+
remotePatterns.push({
78+
protocol: "https",
79+
hostname: `${process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID}.thirdwebstorage-dev.com`,
80+
});
81+
}
82+
return remotePatterns;
8383
}
8484

8585
const SENTRY_OPTIONS: SentryBuildOptions = {
86-
// For all available options, see:
87-
// https://github.com/getsentry/sentry-webpack-plugin#options
86+
// For all available options, see:
87+
// https://github.com/getsentry/sentry-webpack-plugin#options
8888

89-
org: "thirdweb-dev",
90-
project: "dashboard",
91-
// An auth token is required for uploading source maps.
92-
authToken: process.env.SENTRY_AUTH_TOKEN,
93-
// Suppresses source map uploading logs during build
94-
silent: true,
95-
// For all available options, see:
96-
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
89+
org: "thirdweb-dev",
90+
project: "dashboard",
91+
// An auth token is required for uploading source maps.
92+
authToken: process.env.SENTRY_AUTH_TOKEN,
93+
// Suppresses source map uploading logs during build
94+
silent: true,
95+
// For all available options, see:
96+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
9797

98-
// Upload a larger set of source maps for prettier stack traces (increases build time)
99-
widenClientFileUpload: true,
98+
// Upload a larger set of source maps for prettier stack traces (increases build time)
99+
widenClientFileUpload: true,
100100

101-
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
102-
tunnelRoute: "/err",
101+
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
102+
tunnelRoute: "/err",
103103

104-
// Hides source maps from generated client bundles
105-
hideSourceMaps: true,
104+
// Hides source maps from generated client bundles
105+
hideSourceMaps: true,
106106

107-
// Automatically tree-shake Sentry logger statements to reduce bundle size
108-
disableLogger: true,
107+
// Automatically tree-shake Sentry logger statements to reduce bundle size
108+
disableLogger: true,
109109

110-
// Enables automatic instrumentation of Vercel Cron Monitors.
111-
// See the following for more information:
112-
// https://docs.sentry.io/product/crons/
113-
// https://vercel.com/docs/cron-jobs
114-
automaticVercelMonitors: false,
110+
// Enables automatic instrumentation of Vercel Cron Monitors.
111+
// See the following for more information:
112+
// https://docs.sentry.io/product/crons/
113+
// https://vercel.com/docs/cron-jobs
114+
automaticVercelMonitors: false,
115115
};
116116

117117
const baseNextConfig: NextConfig = {
118-
serverExternalPackages: ["pino-pretty"],
119-
async headers() {
120-
return [
121-
{
122-
// Apply these headers to all routes in your application.
123-
source: "/(.*)",
124-
headers: [
125-
...securityHeaders,
126-
{
127-
key: "accept-ch",
128-
value: "sec-ch-viewport-width",
129-
},
130-
],
131-
},
132-
];
133-
},
134-
async redirects() {
135-
return getRedirects();
136-
},
137-
async rewrites() {
138-
return [
139-
{
140-
source: "/thirdweb.eth",
141-
destination: "/deployer.thirdweb.eth",
142-
},
143-
{
144-
source: "/thirdweb.eth/:path*",
145-
destination: "/deployer.thirdweb.eth/:path*",
146-
},
147-
// re-write /home to / (this is so that logged in users will be able to go to /home and NOT be redirected to the logged in app)
148-
{
149-
source: "/home",
150-
destination: "/",
151-
},
152-
...FRAMER_PATHS.map((path) => ({
153-
source: path,
154-
destination: `https://landing.thirdweb.com${path}`,
155-
})),
156-
];
157-
},
158-
images: {
159-
dangerouslyAllowSVG: true,
160-
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
161-
remotePatterns: [
162-
{
163-
protocol: "https",
164-
hostname: "**.thirdweb.com",
165-
},
166-
...determineIpfsGateways(),
167-
],
168-
},
169-
compiler: {
170-
emotion: true,
171-
},
172-
reactStrictMode: true,
118+
serverExternalPackages: ["pino-pretty"],
119+
async headers() {
120+
return [
121+
{
122+
// Apply these headers to all routes in your application.
123+
source: "/(.*)",
124+
headers: [
125+
...securityHeaders,
126+
{
127+
key: "accept-ch",
128+
value: "sec-ch-viewport-width",
129+
},
130+
],
131+
},
132+
];
133+
},
134+
async redirects() {
135+
return getRedirects();
136+
},
137+
async rewrites() {
138+
return [
139+
{
140+
source: "/thirdweb.eth",
141+
destination: "/deployer.thirdweb.eth",
142+
},
143+
{
144+
source: "/thirdweb.eth/:path*",
145+
destination: "/deployer.thirdweb.eth/:path*",
146+
},
147+
// re-write /home to / (this is so that logged in users will be able to go to /home and NOT be redirected to the logged in app)
148+
{
149+
source: "/home",
150+
destination: "/",
151+
},
152+
...FRAMER_PATHS.map((path) => ({
153+
source: path,
154+
destination: `https://landing.thirdweb.com${path}`,
155+
})),
156+
];
157+
},
158+
images: {
159+
dangerouslyAllowSVG: true,
160+
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
161+
remotePatterns: [
162+
{
163+
protocol: "https",
164+
hostname: "**.thirdweb.com",
165+
},
166+
...determineIpfsGateways(),
167+
],
168+
},
169+
compiler: {
170+
emotion: true,
171+
},
172+
reactStrictMode: true,
173173
};
174174

175175
function getConfig(): NextConfig {
176-
if (process.env.NODE_ENV === "production") {
177-
// eslint-disable-next-line @typescript-eslint/no-var-requires
178-
const withBundleAnalyzer = require("@next/bundle-analyzer")({
179-
enabled: process.env.ANALYZE === "true",
180-
});
181-
// eslint-disable-next-line @typescript-eslint/no-var-requires
182-
const { withPlausibleProxy } = require("next-plausible");
183-
// eslint-disable-next-line @typescript-eslint/no-var-requires
184-
const { withSentryConfig } = require("@sentry/nextjs");
185-
return withBundleAnalyzer(
186-
withPlausibleProxy({
187-
customDomain: "https://pl.thirdweb.com",
188-
scriptName: "pl",
189-
})(
190-
withSentryConfig(
191-
{
192-
...baseNextConfig,
193-
experimental: {
194-
webpackBuildWorker: true,
195-
webpackMemoryOptimizations: true,
196-
},
197-
// @ts-expect-error - this is a valid option
198-
webpack: (config) => {
199-
if (config.cache) {
200-
config.cache = Object.freeze({
201-
type: "filesystem",
202-
maxMemoryGenerations: 0,
203-
});
204-
config.cache = Object.freeze({
205-
type: "memory",
206-
});
207-
}
208-
config.externals.push("pino-pretty");
209-
config.module = {
210-
...config.module,
211-
exprContextCritical: false,
212-
};
213-
// Important: return the modified config
214-
return config;
215-
},
216-
},
217-
SENTRY_OPTIONS,
218-
),
219-
),
220-
);
221-
}
222-
// otherwise return the base
223-
return baseNextConfig;
176+
if (process.env.NODE_ENV === "production") {
177+
// eslint-disable-next-line @typescript-eslint/no-var-requires
178+
const withBundleAnalyzer = require("@next/bundle-analyzer")({
179+
enabled: process.env.ANALYZE === "true",
180+
});
181+
// eslint-disable-next-line @typescript-eslint/no-var-requires
182+
const { withPlausibleProxy } = require("next-plausible");
183+
// eslint-disable-next-line @typescript-eslint/no-var-requires
184+
const { withSentryConfig } = require("@sentry/nextjs");
185+
return withBundleAnalyzer(
186+
withPlausibleProxy({
187+
customDomain: "https://pl.thirdweb.com",
188+
scriptName: "pl",
189+
})(
190+
withSentryConfig(
191+
{
192+
...baseNextConfig,
193+
experimental: {
194+
webpackBuildWorker: true,
195+
webpackMemoryOptimizations: true,
196+
},
197+
// @ts-expect-error - this is a valid option
198+
webpack: (config) => {
199+
if (config.cache) {
200+
config.cache = Object.freeze({
201+
type: "memory",
202+
});
203+
}
204+
config.externals.push("pino-pretty");
205+
config.module = {
206+
...config.module,
207+
exprContextCritical: false,
208+
};
209+
// Important: return the modified config
210+
return config;
211+
},
212+
},
213+
SENTRY_OPTIONS,
214+
),
215+
),
216+
);
217+
}
218+
// otherwise return the base
219+
return baseNextConfig;
224220
}
225221

226222
export default getConfig();

0 commit comments

Comments
 (0)