-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathnext.config.js
More file actions
402 lines (388 loc) · 11.5 KB
/
next.config.js
File metadata and controls
402 lines (388 loc) · 11.5 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/**
* @copyright 2024-2026 nirholas. All rights reserved.
* @license SPDX-License-Identifier: SEE LICENSE IN LICENSE
* @see https://github.com/nirholas/free-crypto-news
*
* This file is part of free-crypto-news.
* Unauthorized copying, modification, or distribution is strictly prohibited.
* For licensing inquiries: nirholas@users.noreply.github.com
*/
const createNextIntlPlugin = require('next-intl/plugin');
const withNextIntl = createNextIntlPlugin('./src/i18n/request.ts');
/** @type {import('next').NextConfig} */
const nextConfig = {
// Enable standalone output only for Docker builds; Vercel ignores it but it
// increases build time and conflicts with edge routes.
...(process.env.DOCKER_BUILD === '1' ? { output: 'standalone' } : {}),
// Compress responses
compress: true,
// Security headers
async headers() {
return [
{
// Apply to all routes except /embed/*
source: '/:path((?!embed).*)',
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: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
// CSP is set dynamically by middleware (nonce-based).
// Do NOT add a static Content-Security-Policy header here — it
// would conflict with the per-request nonce generated in middleware.ts.
],
},
{
// Embed widgets — allow cross-origin iframing
source: '/embed/:path*',
headers: [
{
key: 'X-DNS-Prefetch-Control',
value: 'on',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'Access-Control-Allow-Origin',
value: '*',
},
{
key: 'Content-Security-Policy',
value: 'frame-ancestors *',
},
],
},
// ================================================================
// AI Discoverability — llms.txt, robots.txt, .well-known, ai.txt
// ================================================================
{
source: '/llms.txt',
headers: [
{ key: 'Content-Type', value: 'text/plain; charset=utf-8' },
{
key: 'Cache-Control',
value: 'public, max-age=3600, stale-while-revalidate=86400',
},
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'X-Robots-Tag', value: 'noindex' },
],
},
{
source: '/llms-full.txt',
headers: [
{ key: 'Content-Type', value: 'text/plain; charset=utf-8' },
{
key: 'Cache-Control',
value: 'public, max-age=3600, stale-while-revalidate=86400',
},
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'X-Robots-Tag', value: 'noindex' },
],
},
{
source: '/robots.txt',
headers: [
{ key: 'Content-Type', value: 'text/plain; charset=utf-8' },
{ key: 'Cache-Control', value: 'public, max-age=86400' },
],
},
{
source: '/ai.txt',
headers: [
{ key: 'Content-Type', value: 'text/plain; charset=utf-8' },
{ key: 'Cache-Control', value: 'public, max-age=86400' },
{ key: 'Access-Control-Allow-Origin', value: '*' },
],
},
{
source: '/.well-known/:file*',
headers: [
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Cache-Control', value: 'public, max-age=3600' },
],
},
{
// 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: '*', // Public API — allow all origins including AI agents (GPTBot, ClaudeBot, etc.)
},
{
key: 'Access-Control-Allow-Methods',
value: 'GET, POST, OPTIONS',
},
{
key: 'Access-Control-Allow-Headers',
value:
'Content-Type, Authorization, x-api-key, x-speraxos-signature, x-speraxos-timestamp, x-speraxos-nonce, x-speraxos-key-id, x-speraxos-body-hash',
},
{
key: 'Access-Control-Max-Age',
value: '86400',
},
{
key: 'X-RateLimit-Policy',
value: 'fair-use',
},
],
},
{
// Fallback static files — served when all upstreams are down
source: '/fallback/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=60, stale-while-revalidate=86400',
},
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Content-Type', value: 'application/json' },
{ key: 'X-Fallback', value: '1' },
],
},
];
},
// ================================================================
// Redirects — /docs → external docs site
// ================================================================
async redirects() {
return [
// /docs → external docs site
{
source: '/docs',
destination: 'https://docs.cryptocurrency.cv',
permanent: true,
},
{
source: '/docs/:path*',
destination: 'https://docs.cryptocurrency.cv/:path*',
permanent: true,
},
// Fix double-dashboard paths (e.g. /dashboard/dashboard/keys → /dashboard/keys)
{
source: '/dashboard/dashboard',
destination: '/dashboard',
permanent: true,
},
{
source: '/dashboard/dashboard/:path*',
destination: '/dashboard/:path*',
permanent: true,
},
// Locale-prefixed double-dashboard
{
source: '/:locale/dashboard/dashboard',
destination: '/:locale/dashboard',
permanent: true,
},
{
source: '/:locale/dashboard/dashboard/:path*',
destination: '/:locale/dashboard/:path*',
permanent: true,
},
// Common misrouted API paths → correct endpoints (permanent redirects)
{
source: '/api/ai/sentiment',
destination: '/api/sentiment',
permanent: true,
},
{
source: '/api/news/latest',
destination: '/api/news',
permanent: true,
},
{
source: '/api/market/fear-greed',
destination: '/api/fear-greed',
permanent: true,
},
{
source: '/api/v1/posts',
destination: '/api/v1/news',
permanent: true,
},
];
},
// ================================================================
// Rewrites — /llms-full.txt → dynamic API route (static file fallback)
// ================================================================
async rewrites() {
return {
// beforeFiles: runs before Next.js checks public/ static files,
// so the dynamic API route always wins over public/llms-full.txt.
beforeFiles: [
{
source: '/openapi.json',
destination: '/api/openapi.json',
},
{
source: '/llms-full.txt',
destination: '/api/llms-full.txt',
},
{
source: '/.well-known/x402',
destination: '/api/.well-known/x402',
},
{
source: '/.well-known/agents.json',
destination: '/api/well-known/agents',
},
{
source: '/.well-known/agent.json',
destination: '/api/well-known/agents',
},
{
source: '/.well-known/ai-plugin.json',
destination: '/api/well-known/ai-plugin',
},
// Common convenience aliases
{
source: '/rss',
destination: '/api/rss',
},
{
source: '/api/ethereum',
destination: '/api/news?category=ethereum',
},
],
afterFiles: [],
fallback: [],
};
},
// Skip type-checking during build — run `bun run typecheck` separately
typescript: {
ignoreBuildErrors: true,
},
// 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
remotePatterns: [
// Allow all HTTPS images — this aggregator pulls from 100+ RSS feed
// domains whose image CDNs cannot be exhaustively enumerated.
{ protocol: 'https', hostname: '**' },
],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384, 640],
},
// Exclude large directories from output file tracing (Vercel build size)
outputFileTracingExcludes: {
'*': [
'./archive/**',
'./docs/**',
'./e2e/**',
'./stories/**',
'./scripts/**',
'./playwright-report/**',
],
},
// Keep heavy server-only packages out of the client bundle (top-level in Next.js 15+)
serverExternalPackages: [
'pino',
'pino-pretty',
'sharp',
'redis',
'sanitize-html',
'dompurify',
'ws',
'@opentelemetry/api',
'@opentelemetry/sdk-node',
'@opentelemetry/sdk-trace-node',
'@opentelemetry/exporter-trace-otlp-http',
],
// Experimental features for better performance
experimental: {
// Enable optimized loading of CSS
optimizeCss: true,
// Client-side router cache: RSC payloads for dynamic routes survive 30 s,
// static routes survive 3 min — reduces redundant network round-trips on navigation.
staleTimes: {
dynamic: 60,
static: 300,
},
},
// Reduce bundle size via tree-shakeable per-member imports
// Note: recharts is intentionally excluded — its /es6/ subpath is not
// resolvable by Turbopack; import directly from 'recharts' instead.
modularizeImports: {
'lucide-react': {
transform: 'lucide-react/dist/esm/icons/{{kebabCase member}}',
},
},
};
module.exports = withNextIntl(nextConfig);