-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnext.config.js
More file actions
390 lines (363 loc) · 11.6 KB
/
Copy pathnext.config.js
File metadata and controls
390 lines (363 loc) · 11.6 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
/** @type {import('next').NextConfig} */
const path = require('path');
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
options: {
remarkPlugins: [],
rehypePlugins: [],
// Remove providerImportSource to avoid client component issues
},
});
let withBundleAnalyzer = config => config;
try {
withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
} catch (error) {
console.log('Bundle analyzer not available, skipping...');
}
const nextConfig = {
// ESLint is a devDependency — lint in CI, skip during the build
eslint: {
ignoreDuringBuilds: true,
},
// Fix workspace root detection to prevent watching entire home directory
outputFileTracingRoot: __dirname,
// Blog posts are read from content/blog at request time (src/lib/blog.ts).
// File tracing only follows require/import graphs, so the standalone build
// shipped WITHOUT the mdx files — every post rendered as a frontmatter-less
// stub in prod. Explicitly include them for every route that reads them.
outputFileTracingIncludes: {
'/blog': ['./content/blog/**'],
'/blog/[slug]': ['./content/blog/**'],
},
// Support MDX files
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
// Externalize Supabase packages for server-side rendering
// 'standalone' output is what the Hetzner self-host needs — opt in via
// SELF_HOST=1 at build time.
...(process.env.SELF_HOST ? { output: 'standalone' } : {}),
// tiny-secp256k1 is wasm-backed — bundling it breaks the .wasm file's path,
// so it (and the bitcoin libs that wrap it) must stay external and load from
// node_modules at runtime (output file tracing carries them into standalone).
serverExternalPackages: [
'@supabase/supabase-js',
'@supabase/ssr',
'tiny-secp256k1',
'bip32',
'bitcoinjs-lib',
],
// Image optimization
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.unsplash.com',
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: 'github.com',
port: '',
pathname: '/**',
},
{
// Self-hosted Supabase storage on Hetzner — the SSOT.
// Managed-cloud host (ohkueislstxomdjavyhs.supabase.co) retired 2026-06.
protocol: 'https',
hostname: 'supabase.orangecat.ch',
port: '',
pathname: '/storage/v1/object/public/**',
},
],
formats: ['image/webp', 'image/avif'],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
minimumCacheTTL: 31536000, // 1 year
dangerouslyAllowSVG: false,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
// Experimental features for performance
experimental: {
optimizePackageImports: ['lucide-react', 'framer-motion', '@radix-ui/react-dropdown-menu'],
},
// Enable compression
compress: true,
// Generate ETags for better caching (disabled in dev to prevent stale content)
generateEtags: process.env.NODE_ENV === 'production',
// Redirects for common auth URLs
async redirects() {
return [
// Auth redirects - common patterns to canonical /auth page
{
source: '/login',
destination: '/auth?mode=login',
permanent: true,
},
{
source: '/signin',
destination: '/auth?mode=login',
permanent: true,
},
{
source: '/register',
destination: '/auth?mode=register',
permanent: true,
},
{
source: '/signup',
destination: '/auth?mode=register',
permanent: true,
},
{
source: '/auth/signin',
destination: '/auth?mode=login',
permanent: true,
},
{
source: '/auth/signup',
destination: '/auth?mode=register',
permanent: true,
},
{
source: '/auth/login',
destination: '/auth?mode=login',
permanent: true,
},
{
source: '/auth/register',
destination: '/auth?mode=register',
permanent: true,
},
// The standalone forgot-password page duplicated the in-form flow
// (two surfaces, one purpose). /auth?mode=forgot is the one surface.
{
source: '/auth/forgot-password',
destination: '/auth?mode=forgot',
permanent: true,
},
// Legacy per-assistant chat routes — superseded by /dashboard/cat.
// No inbound links from the app; preserved here in case bookmarks exist.
{
source: '/ai-chat/:path*',
destination: '/dashboard/cat',
permanent: true,
},
// Guessable aliases for the flagship Cat surface. "The Cat is the
// interface" — someone typing orangecat.ch/cat must land on the Cat,
// never on a 404. Same alias policy as the /login → /auth block above.
{
source: '/cat',
destination: '/dashboard/cat',
permanent: true,
},
{
source: '/chat',
destination: '/dashboard/cat',
permanent: true,
},
{
source: '/ai',
destination: '/dashboard/cat',
permanent: true,
},
];
},
// Enhanced headers for performance
async headers() {
const isDevelopment = process.env.NODE_ENV !== 'production';
return [
{
source: '/(.*)',
headers: [
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
// HSTS: tell browsers to always use HTTPS (production only)
...(!isDevelopment
? [
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
// Content-Security-Policy in REPORT-ONLY first: it never blocks,
// only reports violations, so we can tune the policy against real
// traffic before switching to an enforcing `Content-Security-Policy`
// header. The app renders user-generated content, so an XSS-limiting
// CSP is the biggest header-layer gap. connect-src covers the
// self-hosted Supabase (REST + realtime ws) and R2 media.
{
key: 'Content-Security-Policy-Report-Only',
value: [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' 'unsafe-eval'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https:",
"font-src 'self' data:",
"connect-src 'self' https://supabase.orangecat.ch wss://supabase.orangecat.ch https://*.cloudflarestorage.com",
"frame-ancestors 'none'",
"base-uri 'self'",
"form-action 'self'",
"object-src 'none'",
].join('; '),
},
]
: []),
// Disable caching in development
...(isDevelopment
? [
{
key: 'Cache-Control',
value: 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0',
},
]
: []),
],
},
{
source: '/static/(.*)',
headers: [
{
key: 'Cache-Control',
value: isDevelopment
? 'no-store, no-cache, must-revalidate'
: 'public, max-age=31536000, immutable',
},
],
},
// Disable caching for all JS/CSS in development
...(isDevelopment
? [
{
source: '/_next/static/(.*)',
headers: [
{
key: 'Cache-Control',
value: 'no-store, no-cache, must-revalidate',
},
],
},
]
: []),
];
},
// Production optimizations
...(process.env.NODE_ENV === 'production' && {
compiler: {
removeConsole: {
exclude: ['error', 'warn'],
},
},
}),
// TypeScript and ESLint validation enabled for code quality
typescript: {
// Block production builds on type errors
ignoreBuildErrors: false,
},
// Remove X-Powered-By header
poweredByHeader: false,
// Performance budgets
onDemandEntries: {
maxInactiveAge: 25 * 1000,
pagesBufferLength: 2,
},
// Advanced webpack optimizations for bundle size
webpack: (config, options) => {
const { dev, isServer, webpack } = options;
// Prevent watching parent directories to avoid EMFILE errors
// Use polling mode for better reliability with large projects
if (dev) {
config.watchOptions = {
...config.watchOptions,
ignored: [
// Ignore common build/cache directories
'**/node_modules/**',
'**/.git/**',
'**/.next/**',
'**/mcp-servers/**',
'**/test-results/**',
'**/logs/**',
'**/.playwright-mcp/**',
'**/*.log',
'**/*.tmp',
'**/*.cache',
'**/__pycache__/**',
'**/coverage/**',
'**/dist/**',
'**/build/**',
'**/migration-testing/**',
'**/cypress/**',
'**/playwright-report/**',
],
followSymlinks: false,
aggregateTimeout: 500,
// Use polling to avoid EMFILE errors - more reliable for large projects
// Polling checks files periodically instead of watching all file descriptors
// This prevents "too many open files" errors on Linux systems
poll: 1000, // Poll every 1 second (1000ms)
};
}
// Note: Manual webpack externals REMOVED - they caused build issues.
// Supabase packages are handled via serverExternalPackages config instead
// Configure fallbacks for Node.js polyfills (only for client-side)
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
net: false,
tls: false,
crypto: false,
stream: false,
url: false,
zlib: false,
http: false,
https: false,
assert: false,
os: false,
path: false,
};
// Simple global polyfills and environment variables
config.plugins.push(
new webpack.DefinePlugin({
global: 'globalThis',
self: 'globalThis',
'process.env.NEXT_PUBLIC_SUPABASE_URL': JSON.stringify(
process.env.NEXT_PUBLIC_SUPABASE_URL
),
'process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY': JSON.stringify(
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
),
})
);
}
// Note: if needed, aliases can be added here
return config;
},
};
module.exports = withBundleAnalyzer(withMDX(nextConfig));
// Performance monitoring
if (process.env.NODE_ENV === 'production') {
console.log('🚀 Performance optimizations enabled:');
console.log(' ✅ SWC Minification');
console.log(' ✅ Image Optimization');
console.log(' ✅ Advanced Tree Shaking');
console.log(' ✅ Smart Code Splitting');
console.log(' ✅ Compression');
console.log(' ✅ Enhanced Caching Headers');
console.log(' ✅ Bundle Size Optimization');
// Cache-busting deployment: 2025-10-30T20:17
}