-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
331 lines (310 loc) · 8.58 KB
/
next.config.ts
File metadata and controls
331 lines (310 loc) · 8.58 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
import type { NextConfig } from "next";
/**
* Production-ready Next.js configuration optimized for Google Drive Index applications
*
* Key optimizations:
* - Google Drive API caching and rate limiting
* - Large file streaming and thumbnail optimization
* - Cloudflare Workers compatibility
* - Security headers for file serving
* - Bundle splitting for Google APIs
* - Performance monitoring and analytics
*/
const nextConfig: NextConfig = {
// Basic Configuration
reactStrictMode: true,
pageExtensions: ["tsx", "ts"],
// Performance Optimizations
poweredByHeader: false,
generateEtags: true,
// Cloudflare Workers Optimization
output: "standalone",
// Performance Monitoring
experimental: {
optimizePackageImports: [
"@radix-ui/react-icons",
"@radix-ui/react-dialog",
"@radix-ui/react-dropdown-menu",
"@radix-ui/react-popover",
"@radix-ui/react-select",
"@radix-ui/react-tooltip",
"lucide-react",
"date-fns",
"react-markdown",
"framer-motion",
"@tanstack/react-virtual",
],
nodeMiddleware: true,
// Server Actions optimization for Google Drive API
serverActions: {
allowedOrigins: ["localhost:3000", process.env.VERCEL_URL || ""],
bodySizeLimit: "10mb", // Large file metadata
},
// Optimize for file serving
optimizeServerReact: true,
// Experimental performance features
webVitalsAttribution: ["CLS", "FCP", "FID", "INP", "LCP", "TTFB"],
},
// Image Optimization (Google Drive + Cloudflare optimized)
images: {
formats: ["image/avif", "image/webp"],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
minimumCacheTTL: 31536000, // 1 year
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
// Google Drive thumbnails and external domains
remotePatterns: [
{
protocol: "https",
hostname: "drive.google.com",
pathname: "/thumbnail**",
},
{
protocol: "https",
hostname: "lh3.googleusercontent.com",
pathname: "**",
},
{
protocol: "https",
hostname: "docs.google.com",
pathname: "**",
},
],
unoptimized: false,
},
// Bundle Optimization
// Turbopack Configuration (Next.js 15+)
turbopack: {
resolveExtensions: [".mdx", ".tsx", ".ts", ".jsx", ".js", ".mjs", ".json"],
},
// Compiler Optimizations
compiler: {
removeConsole:
process.env.NODE_ENV === "production"
? {
exclude: ["error", "warn"],
}
: false,
// React compiler optimization (if available)
reactRemoveProperties:
process.env.NODE_ENV === "production"
? {
properties: ["^data-testid$"],
}
: false,
},
// Security Headers + Google Drive Optimization
async headers() {
return [
{
source: "/(.*)",
headers: [
{
key: "X-Frame-Options",
value: "DENY",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "X-XSS-Protection",
value: "1; mode=block",
},
{
key: "Referrer-Policy",
value: "strict-origin-when-cross-origin",
},
{
key: "Permissions-Policy",
value:
"camera=(), microphone=(), geolocation=(), browsing-topics=()",
},
],
},
// Google Drive API routes - Short cache with background refresh
{
source: "/api/(files|search|paths)/(.*)",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=300, stale-while-revalidate=900", // 5min cache, 15min stale
},
],
},
// File downloads - Long cache for immutable content
{
source: "/api/(download|raw)/(.*)",
headers: [
{
key: "Cache-Control",
value:
"public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800", // 1hr, 1day, 1week
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
],
},
// Thumbnails - Very long cache
{
source: "/api/(thumb|og)/(.*)",
headers: [
{
key: "Cache-Control",
value: "public, max-age=2592000, s-maxage=31536000, immutable", // 30days, 1year
},
],
},
// Other API routes
{
source: "/api/(.*)",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=60, stale-while-revalidate=300", // 1min cache, 5min stale
},
],
},
// Static assets
{
source:
"/(_next/static/.*|favicon.ico|favicon.png|favicon.svg|logo.svg)",
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
],
},
];
},
// Webpack Configuration
webpack: (config, { dev, isServer }) => {
// Optimize bundle size
config.optimization = {
...config.optimization,
splitChunks: {
chunks: "all",
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
priority: 10,
reuseExistingChunk: true,
},
// Google APIs and Drive-specific libraries
googleapis: {
test: /[\\/]node_modules[\\/](googleapis|@google-cloud)[\\/]/,
name: "googleapis",
priority: 15,
reuseExistingChunk: true,
},
// Media handling libraries
media: {
test: /[\\/]node_modules[\\/](fflate|@vidstack)[\\/]/,
name: "media",
priority: 12,
reuseExistingChunk: true,
},
// UI components
ui: {
test: /[\\/]node_modules[\\/](@radix-ui|lucide-react)[\\/]/,
name: "ui",
priority: 11,
reuseExistingChunk: true,
},
common: {
minChunks: 2,
priority: 5,
reuseExistingChunk: true,
},
},
},
};
// Performance monitoring in development
if (dev && !isServer) {
config.optimization.concatenateModules = false; // Better for debugging
}
// Optimize for large file handling
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
net: false,
tls: false,
};
return config;
},
// TypeScript Configuration
typescript: {
ignoreBuildErrors: false,
},
// ESLint Configuration
eslint: {
ignoreDuringBuilds: false,
},
// Redirects for better SEO and UX
async redirects() {
return [
{
source: "/home",
destination: "/",
permanent: true,
},
// Legacy Google Drive URLs redirect
{
source: "/drive/:path*",
destination: "/:path*",
permanent: true,
},
// File viewer redirect (common pattern)
{
source: "/file/:path*",
destination: "/:path*",
permanent: true,
},
// Directory listing redirect
{
source: "/folder/:path*",
destination: "/:path*",
permanent: true,
},
];
},
// Environment Variables
env: {
CUSTOM_KEY: process.env.CUSTOM_KEY || "",
// Google Drive API optimization
GOOGLE_DRIVE_API_TIMEOUT: process.env.GOOGLE_DRIVE_API_TIMEOUT || "30000",
// Enable streaming for large files
ENABLE_FILE_STREAMING: process.env.ENABLE_FILE_STREAMING || "true",
// Performance monitoring
ENABLE_PERFORMANCE_MONITORING:
process.env.ENABLE_PERFORMANCE_MONITORING || "false",
},
// Server-side configuration for Google Drive
serverRuntimeConfig: {
// Google Drive API connection settings
googleDriveTimeout: 30000,
maxFileSize: 100 * 1024 * 1024, // 100MB default
chunkSize: 1024 * 1024, // 1MB chunks for streaming
},
// Public runtime config
publicRuntimeConfig: {
// Cache settings for client-side
thumbnailCacheTTL: 3600000, // 1 hour
fileListCacheTTL: 300000, // 5 minutes
// Performance monitoring
performanceMonitoring: process.env.ENABLE_PERFORMANCE_MONITORING === "true",
},
// Development Configuration
...(process.env.NODE_ENV === "development" && {
onDemandEntries: {
maxInactiveAge: 25 * 1000,
pagesBufferLength: 2,
},
}),
};
export default nextConfig;