Repository navigation
Expand file tree
/
Copy pathnext.config.js
More file actions
148 lines (144 loc) · 5.21 KB
/
Copy pathnext.config.js
File metadata and controls
148 lines (144 loc) · 5.21 KB
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
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const { withSentryConfig } = require('@sentry/nextjs');
const withPWA = require('@ducanh2912/next-pwa').default({
dest: 'public',
disable: process.env.NODE_ENV === 'development',
});
/** @type {import('next').NextConfig} */
// CDN host for static assets (/_next/static/*, /public/*). When unset,
// Next.js serves assets from the app's own origin — i.e. it "falls back to
// origin" automatically, so leaving CDN_ASSET_PREFIX unconfigured is a safe
// default for local dev / CI, not a broken state.
const cdnAssetPrefix = process.env.CDN_ASSET_PREFIX || undefined;
const nextConfig = {
// Gzip/Brotli-compress all server responses (HTML, JSON API payloads, etc.)
// to cut payload size for slower / mobile connections.
compress: true,
// Serve build output (JS/CSS chunks) from a CDN when configured. Next.js
// fingerprints these files with content hashes, so swapping the prefix on
// deploy is automatic cache-busting / versioning — no manual query strings.
assetPrefix: cdnAssetPrefix,
experimental: {
serverComponentsExternalPackages: ['@stellar/stellar-sdk', '@vercel/blob'],
},
images: {
// Serve modern formats where the browser supports them; falls back
// automatically for browsers that don't.
formats: ["image/webp"],
// Recipient avatars fall back to Gravatar; served unoptimized so no image
// requests are proxied through the Next.js optimizer.
remotePatterns: [
{
protocol: 'https',
hostname: 'www.gravatar.com',
pathname: '/avatar/**',
},
],
},
async headers() {
return [
{
source: '/:path*',
headers: [
{ key: 'X-Frame-Options', value: 'DENY' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
// X-XSS-Protection enables the browser's built-in XSS filter (IE/Chrome legacy).
// Modern browsers rely on CSP instead, but this header provides defence-in-depth
// for older clients. Mode=block prevents partial rendering of detected attacks.
{ key: 'X-XSS-Protection', value: '1; mode=block' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=(), payment=(self)',
},
],
},
{
source: '/sw.js',
headers: [
{ key: 'Cache-Control', value: 'no-cache, no-store, must-revalidate' },
{ key: 'Service-Worker-Allowed', value: '/' },
],
},
{
source: '/embed/:id',
headers: [
{ key: 'X-Frame-Options', value: 'ALLOWALL' },
],
},
{
// Next.js fingerprints build assets with content hashes, so they're
// safe to cache aggressively and immutably on the client/CDN.
source: "/_next/static/:path*",
headers: [
{ key: "Cache-Control", value: "public, max-age=31536000, immutable" },
],
},
{
// Fingerprinted static files under /public (images, fonts, icons).
source: "/:path*.(svg|jpg|jpeg|png|webp|avif|gif|ico|woff|woff2|ttf|otf)",
headers: [
{ key: "Cache-Control", value: "public, max-age=31536000, immutable" },
],
},
{
// JSON API responses: allow short-lived shared caching + revalidation
// instead of forcing every client to refetch from origin.
source: "/api/:path*",
headers: [
{ key: "Cache-Control", value: "private, max-age=0, must-revalidate" },
],
},
];
},
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
net: false,
tls: false,
};
}
config.externals = [
...(Array.isArray(config.externals) ? config.externals : []),
'sodium-native',
...(isServer
? [
{ '@stellar/stellar-sdk': 'commonjs2 @stellar/stellar-sdk' },
{ '@vercel/blob': 'commonjs2 @vercel/blob' },
]
: []),
];
config.resolve.alias = {
...config.resolve.alias,
'@apm-js-collab/tracing-hooks': false,
};
return config;
},
};
const sentryWebpackPluginOptions = {
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
silent: true,
// Hide source maps from the client bundle; they are uploaded to Sentry instead.
hideSourceMaps: true,
// Upload source maps for all client files, not just the ones referenced in the bundle.
widenClientFileUpload: true,
// Route Sentry requests through a same-origin tunnel to avoid ad-blockers.
tunnelRoute: '/monitoring',
// Only run the Sentry webpack plugins when a DSN is configured.
disableServerWebpackPlugin: !process.env.NEXT_PUBLIC_SENTRY_DSN,
disableClientWebpackPlugin: !process.env.NEXT_PUBLIC_SENTRY_DSN,
};
module.exports = withSentryConfig(
withBundleAnalyzer(withPWA(nextConfig)),
sentryWebpackPluginOptions
);