-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathnext.config.js
More file actions
86 lines (75 loc) · 2.43 KB
/
Copy pathnext.config.js
File metadata and controls
86 lines (75 loc) · 2.43 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
// Validate required environment variables at build time.
// If any are missing the build aborts with a clear error rather than
// producing a bundle that fails silently at runtime.
const { z } = require('zod');
const envSchema = z.object({
NEXT_PUBLIC_API_URL: z
.string()
.min(1, 'NEXT_PUBLIC_API_URL must not be empty')
.url('NEXT_PUBLIC_API_URL must be a valid URL'),
});
const envResult = envSchema.safeParse({
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
});
if (!envResult.success) {
const issues = envResult.error.issues
.map((e) => ` - ${e.path.join('.')}: ${e.message}`)
.join('\n');
throw new Error(`\nMissing or invalid environment variables:\n${issues}\n`);
}
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
/** @type {import('next').NextConfig} */
const nextConfig = {
// Next.js 16 uses Turbopack by default, which handles chunk splitting
// and minification automatically (no swcMinify / custom webpack needed).
// Enable experimental features for better performance
experimental: {
optimizePackageImports: ['react', 'react-dom'],
},
// Compress responses
compress: true,
// Generate ETags for caching
generateEtags: true,
// Optimize images
images: {
formats: ['image/avif', 'image/webp'],
},
// Security headers
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
{
key: 'Permissions-Policy',
value: 'geolocation=(), microphone=(), camera=()',
},
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
// Content-Security-Policy is intentionally NOT set here. It is
// computed per-request in src/proxy.ts, which needs a fresh nonce
// and the runtime API origin for connect-src — values this static
// config cannot supply. Defining it in both places would mean two
// divergent policies write the same header for the same routes.
],
},
];
},
};
module.exports = withBundleAnalyzer(nextConfig);