-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathnext.config.js
More file actions
215 lines (207 loc) · 4.89 KB
/
next.config.js
File metadata and controls
215 lines (207 loc) · 4.89 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/** @type {import('next').NextConfig} */
const nextConfig = {
// Compress responses
compress: true,
// Security headers
async headers() {
return [
{
// Apply to all routes
source: '/:path*',
headers: [
{
key: 'X-DNS-Prefetch-Control',
value: 'on',
},
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN', // Changed from DENY to allow PWA features
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
],
},
{
// Service Worker headers
source: '/sw.js',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=0, must-revalidate',
},
{
key: 'Service-Worker-Allowed',
value: '/',
},
],
},
{
// Manifest headers
source: '/manifest.json',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=86400',
},
{
key: 'Content-Type',
value: 'application/manifest+json',
},
],
},
{
// PWA assets headers
source: '/icons/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
// Splash screen headers
source: '/splash/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
// API routes - CORS and caching
source: '/api/:path*',
headers: [
{
key: 'Access-Control-Allow-Origin',
value: '*',
},
{
key: 'Access-Control-Allow-Methods',
value: 'GET, POST, OPTIONS',
},
{
key: 'Access-Control-Allow-Headers',
value: 'Content-Type, Authorization',
},
{
key: 'Access-Control-Max-Age',
value: '86400',
},
{
key: 'X-RateLimit-Policy',
value: 'fair-use',
},
],
},
];
},
// Disable x-powered-by header
poweredByHeader: false,
// Enable React strict mode
reactStrictMode: true,
// Optimize images
images: {
formats: ['image/avif', 'image/webp'],
minimumCacheTTL: 60 * 60 * 24 * 30, // 30 days
},
// Experimental features for better performance
experimental: {
// Enable optimized loading of CSS
optimizeCss: true,
// Limit concurrent static page generation to avoid API rate limits
staticGenerationMaxConcurrency: 1,
},
// Reduce bundle size
modularizeImports: {
lodash: {
transform: 'lodash/{{member}}',
},
},
// URL redirects for SEO
async redirects() {
return [
// Redirect old article IDs to search (for unknown old URLs)
// Note: Specific redirects are handled in the article page itself
// Common URL variations
{
source: '/articles/:id',
destination: '/article/:id',
permanent: true,
},
{
source: '/coins/:id',
destination: '/coin/:id',
permanent: true,
},
{
source: '/categories/:slug',
destination: '/category/:slug',
permanent: true,
},
{
source: '/topics/:slug',
destination: '/topic/:slug',
permanent: true,
},
{
source: '/sources/:slug',
destination: '/source/:slug',
permanent: true,
},
// Trailing slash normalization
{
source: '/blog/',
destination: '/blog',
permanent: true,
},
{
source: '/api/',
destination: '/developers',
permanent: true,
},
{
source: '/docs/',
destination: '/developers',
permanent: true,
},
];
},
// URL rewrites for cleaner URLs
async rewrites() {
return {
beforeFiles: [
// Allow coins to be accessed by symbol (e.g., /coin/btc)
{
source: '/c/:symbol',
destination: '/coin/:symbol',
},
// Short article URLs
{
source: '/a/:id',
destination: '/article/:id',
},
],
};
},
};
module.exports = nextConfig;